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
# 8  
Old 03-03-2010
Quote:
Originally Posted by scottn
awk takes files, or standard input as input, not directories.
Code:
nawk -f ./test.awk /tmp/dir/*

# 9  
Old 03-03-2010
Quote:
Originally Posted by vgersh99
Code:
nawk -f ./test.awk /tmp/dir/*

What does * expand to?

Code:
# mkdir tmp
# mkdir tmp2
# mkdir tmp/1 tmp/2
# echo hello > tmp2/1; echo world > tmp2/2
# awk '{ print $NF }' tmp/*               
(nothing)
# awk '{ print $NF }' tmp2/*
hello
world

# 10  
Old 03-03-2010
That will take all of the content in all of the files. I only need the file names.

In any case, there are better ways to get a list of files in a directory. I'll just use something a little cleaner.

All the same, thanks for checking it out.
# 11  
Old 03-03-2010
Quote:
Originally Posted by scottn
What does * expand to?
What do you think? Smilie
using shell's filename generation it will expand to all the files/directories/links/etc at a given location on a file system.

Quote:
Originally Posted by scottn
Code:
# mkdir tmp
# mkdir tmp2
# mkdir tmp/1 tmp/2
# echo hello > tmp2/1; echo world > tmp2/2
# awk '{ print $NF }' tmp/*               
(nothing)
# awk '{ print $NF }' tmp2/*
hello
world

Are you surprised? Would you expect anything else?
# 12  
Old 03-03-2010
Quote:
Originally Posted by vgersh99
What do you think? Smilie
using shell's filename generation it will expand to all the files/directories/links/etc at a given location on a file system.


Are you surprised? Would you expect anything else?
No, I wouldn't Smilie

But passing awk a directory name in itself (like ~), or a directory which doesn't contain any files, doesn't mean anything to it.

That's all I was saying Smilie

Code:
# echo hello again > tmp/3 
# ls -l tmp
total 8
drwxr-xr-x  2 scottn  staff  68  3 Mar 22:09 1
drwxr-xr-x  2 scottn  staff  68  3 Mar 22:09 2
-rw-r--r--  1 scottn  staff  12  3 Mar 22:28 3

# awk '{ print $NF }' tmp/*
again

# 13  
Old 03-03-2010
ah, we're in violent agreement then!
# 14  
Old 03-03-2010
Happily, yes Smilie

(and sorry that perhaps my initial point was not as clear as it might have been Smilie)
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