Problem passing directory as argument with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem passing directory as argument with awk
# 1  
Old 03-03-2010
Problem passing directory as argument with awk

I'm trying to figure out what's getting passed as the argument when I try to pass a directory as an argument, and I'm getting incredibly strange behavior. For example, from the command line I'm typing:

Code:
nawk -f ./test.awk ~

test.awk contains the following:

Code:
{
  directory = $NF
  print directory;
}

And I get the following output:

.dtprofile
.slickedit
cqcc_cache
search.txt
Command.pm
xcleardiff

These are only a few of the files in my home directory. Other directories return nothing at all even though they have hundreds of files in them. How is this behavior explained? I can't make heads or tails of it.
# 2  
Old 03-03-2010
By specifying -, your telling awk to take its input from standard input. Where does that come from (or rather, how)?

Please show the entire command line you are running.
# 3  
Old 03-03-2010
It's not a dash. It's a tilde, referring to my home directory. That is the entire command line.
# 4  
Old 03-03-2010
Ha ha. Sorry!!! Ich bin blind!

In any case I'm surprised that returns anything (it doesn't on my system).

What are you actually trying to achieve?

For example
Code:
find ~ | awk -f ./test.awk

will show you everything.
# 5  
Old 03-03-2010
Well, I'm actually trying to fix a ksh and an awk script that somebody else wrote. As I understand it, it's supposed to take every file name in a directory and compare times in the file name to determine which ones to parse. The problem is that it's not picking up file names correctly. Apparently it used to work, but we changed the way we're handling time and now it's broken. The part that's odd looks like the following (this is the ksh):

Code:
LOG=`nawk -f /$toolpath/getlog.awk day=$DAY hr=$HR /tmp/dir`

The logs are in /tmp/dir

Inside the getlog.awk file, the first line is as follows:

Code:
logfile = $NF

I was trying to determine what exactly was in logfile, so I made some test scripts and was promptly baffled.
# 6  
Old 03-03-2010
As an aside, while I think about it.... there's not a single tilde in any of that!

I still can't believe this ever worked.

Consider this:

Code:
$ cat file1
4
5

$ awk 1 file1
4
5

$ pwd
/users/home/scottn

$ echo ~
/users/home/scottn

$ ls ~
file1

$ awk 1 ~
(nothing)

$ ls /tmp
(lots of files...)

$ awk 1 /tmp
(nothing)

awk takes files, or standard input as input, not directories.

Last edited by Scott; 03-03-2010 at 04:55 PM..
# 7  
Old 03-03-2010
Right. The tilde was just in my test script. I can put in any directory and I get equally strange results. I tried /tmp and got nothing. I tried the root directory and got 3 files. It seems erratic.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

Passing --usage as argument to awk script

I have the awk script below and things go wrong when I do awk -v dsrmx=25 -f ./checkSRDry.awk --usage I basically want to override the usual --usage and --help that awk gives. How do people usually handle this situation when you also want to supply your own usage and help concerning the... (2 Replies)
Discussion started by: kristinu
2 Replies

3. Shell Programming and Scripting

Passing value as a command line argument in awk script.

I have one working awk command line. Which taking data from the “J1202523.TXT” file and generating the “brazil.dat” file. PFB code. awk '{ DUNS = substr($0,0,9);if ( substr($0,14,3) == "089" ) print DUNS }' J1202523.TXT > Brazil.dat But now I want to pass two parameter as a command line argument... (4 Replies)
Discussion started by: humaemo
4 Replies

4. Shell Programming and Scripting

Passing argument to system call in awk script

So, I have this script. It reads a CSV file that has a mixture of object names with IP addresses (parsing out that part I have working), and object names which have a DNS name. I want to be able to run a "dig +short" based off of the name given to me in the line of the awk script, and then deal... (6 Replies)
Discussion started by: mikesimone
6 Replies

5. Shell Programming and Scripting

passing argument from Cshelll to awk command

Hi all I have got a file digits.data containing the following data 1 3 4 2 4 9 7 3 1 7 3 10 I am writing a script that will pass an argument from C-shell to nawk command. But it seems the values in the nawk comman does not get set. the program does not print no values out. Here is the... (1 Reply)
Discussion started by: ganiel24
1 Replies

6. Shell Programming and Scripting

Problem in argument passing

Hell all, i have a problem in argument passing. print() { a=$1 b=$2 c=$3 echo $a echo $b echo $c } x="1 2 3" y="4 5 6" z="7 8 9" print $x $y $z. (4 Replies)
Discussion started by: tsaravanan
4 Replies

7. Shell Programming and Scripting

passing argument into awk

i'm trying to pass a numerical argument with function xyz to print specfic lines of filename, but my 'awk' syntax is incorrect. ie xyx 3 (prints the 3rd line, separated by ':' of filename) function xyz() { arg1=$1 cat filename | awk -F: -v x=$arg1 '{print $x}' } any ideas? (4 Replies)
Discussion started by: prkfriryce
4 Replies

8. Shell Programming and Scripting

Problem when passing argument to a shell script

Hi all, I'm new to Shell scripting. In my shell script for Bourne shell, the script accepts a date parameter which is optional. If the value is supplied, the supplied value should be assigned to a variable. If not, the current date will be assigned to the variable. My script is like this. #!... (9 Replies)
Discussion started by: sumesh.abraham
9 Replies

9. Shell Programming and Scripting

Problem with Argument Passing

Greetings, I am wrapping the monitoring commands like vmstat, sar, iostat and call via arguments I want ./unix_stats.sh -v vmstat -p <SEC> -d <Duration> to give vmstat values, and similarly iostat etc.,. Also if I give ./unix_stats.sh -v vmstat -i iostat -p <SEC> -d <Duration> should give... (4 Replies)
Discussion started by: A_Rod
4 Replies

10. UNIX for Dummies Questions & Answers

Passing argument to awk script

I am writing a shell script. Now i need to read in a string and send it to an awk file to compare and search for compatible record. I wrote it like tat: read serial | awk -f generate.awk data.dat p/s: the data file got 6 field. According to an expert, we can write it like tat: read... (1 Reply)
Discussion started by: AkumaTay
1 Replies
Login or Register to Ask a Question