passing argument from Cshelll to awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing argument from Cshelll to awk command
# 1  
Old 06-24-2009
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 script run_odd

#!/bin/csh
set var1 = 0
set var2 = 5
nawk '{rl[1]=R1;rl[2]=R2; rr=2-($2%2); if($1>=rl[rr]){print rl[rr]}}' R1=$var1 R2=$var2


I use the following command to execute it
cat digits.data | run_odd

The script is suppose to print out the value of rl[rr] if the first field of digits.data file is >0 and the second filed is an odd number OR if the first field $1>5 and the second field is an even number.

Why does the variables in the nawk not get set?
Thank you.
# 2  
Old 06-24-2009
for awk you have to provide a file name at the end..
or else include your code in BEGIN segment
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing an argument to cut command

Can we pass an argument to cut command as below Suppose cut command is used in for or while loop and we need to pass the incremental counter cut -f$i Here $i is an argument. Like wise it has to come cut -f1 cut -f2 Where i=1,2,3,.... (1 Reply)
Discussion started by: bashamsc
1 Replies

2. 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

3. Shell Programming and Scripting

Passing argument on find command

Hi, I'm trying to pass the variable in the find command like below a=log.20111114 find /apps/file3_logs/env3/ -name '$a' -exec ls -lrt {} \; but it's not working thanks in advance. Regards Thelak (3 Replies)
Discussion started by: ajithbe
3 Replies

4. Programming

Passing argument to command in C

Hello all, New to C and I'm trying to write a program which can run a unix command. Would like to have the option of giving the user the ability to enter arguments e.g for "ls" be able to run "ls -l". I would appreciate any help. Thanks #include <stdio.h> #include <unistd.h> #include... (3 Replies)
Discussion started by: effizy
3 Replies

5. 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

6. Shell Programming and Scripting

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: nawk -f ./test.awk ~ test.awk contains the following: { directory = $NF print... (13 Replies)
Discussion started by: mrplainswalker
13 Replies

7. Shell Programming and Scripting

Need Help with the argument passing Through Command line

$$$$$ (5 Replies)
Discussion started by: asirohi
5 Replies

8. Shell Programming and Scripting

passing a command line argument

I have a shell script which does the encryption of a file where i am passing the file name as a command line argument,but later on the script waits on the screen to enter Y or N what is the command i should be using on the shell script #!/bin/bash -x outfilename=file.out echo... (8 Replies)
Discussion started by: rudoraj
8 Replies

9. 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

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