How do we pass multiple arguments into awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do we pass multiple arguments into awk
# 1  
Old 11-18-2009
How do we pass multiple arguments into awk

How do we pass multiple arguments into awk :

name=john
age=12

now i have to pass both age and name into awk.. how to do it?

like : awk -v var=...
# 2  
Old 11-18-2009
Use -v
Code:
awk -v name=john -v age=12 'BEGIN{print name, age}'

# 3  
Old 11-18-2009
If you don't need to use the variable in the BEGIN patten, you can also do :
Code:
awk 'awk script code' name=john age=12 inputfile

Jean-Pierre.
# 4  
Old 11-18-2009
thanks a lot guys
# 5  
Old 11-18-2009
Quote:
Originally Posted by aigles
If you don't need to use the variable in the BEGIN patten, you can also do :
Code:
awk 'awk script code' name=john age=12 inputfile

Jean-Pierre.
So despite the "BEGIN" drawback, this one has the advantage of being more portable. If you use GNU or Sun's xpg4-awk, -v will work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass command line arguments to awk program?

#!/bin/awk -f BEGIN { FS=":"; } { if ( $7 == "" ) { print $1 ": no password!"; } } I want to execute this program for a particular user to check for his password from the file /etc/passwd (as the input file) and the user details to be given... (1 Reply)
Discussion started by: sri.phani
1 Replies

2. Shell Programming and Scripting

Need to pass shell arguments into Nawk/awk

Hi, I am in critical need of help, Thanks a ton for your help. I need to know how to pass the shell argument into nawk code in AIX. so that my file gets passed into that awk script and it can execute it part. To be detail, i have more than 100 files and in those files a particular field... (6 Replies)
Discussion started by: Selva_2507
6 Replies

3. Shell Programming and Scripting

How can I pass arguments to system command in a awk script?

Hi I need your help, please How can I pass arguments to system command in a awk script?... for example: byte=substr(cadena,pos,2); system("grep -n byte mapeo.txt"); Does it exist a way? Thanks for advance. (4 Replies)
Discussion started by: solaris21
4 Replies

4. UNIX for Dummies Questions & Answers

To pass multiple arguments from file in to an sql query

Hi all , I want to pass contents from a file say f1 as arguments to a sql query which has In statement using a script example select * from table_1 where login in ( `cat f1`) ; will this work or is there any other way to do it. (1 Reply)
Discussion started by: zozoo
1 Replies

5. UNIX for Dummies Questions & Answers

Pass arguments to the library .so

Hello, Please, how can i pass arguments to my lib.so ? my lib.so is written in c and i need some arguments in the code .. LD_PRELOAD=lib.so ./program Thank you. (1 Reply)
Discussion started by: chercheur857
1 Replies

6. Shell Programming and Scripting

pass arguments unchanged

Hi, I have to use ksh on HP-UX for some scripting. I usually use "set -e -u" in scripts to stop if errors occur or a typo is in a variable name. Now I try to use "$@" to pass the arguments unchanged to another function, which works without problems - unless I try to call the script without... (7 Replies)
Discussion started by: michas
7 Replies

7. Shell Programming and Scripting

Pass command line arguments to awk

I am trying to pass max as a sommand line argument when I call awk. Made the modification in the BEGIN but it is not working I'm getting an error as below: awk: txsrx.awk:82: (FILENAME=jcd.tx FNR=4161) fatal: cannot open file `40' for reading (No such file or directory) Somehow it... (2 Replies)
Discussion started by: kristinu
2 Replies

8. Shell Programming and Scripting

need help to pass arguments in script

Hi, I have a my script here-- print "The Perl Script does the User health check and system health check...\n"; print "---------------------------------------------------------------------\n"; # use strict; my($OS); $OS = $^O; # need to test @ARGV before GetOptions shifts it if (@ARGV... (1 Reply)
Discussion started by: namishtiwari
1 Replies

9. UNIX for Advanced & Expert Users

Pass Kill with arguments

Dude, I want to kill a process, but the processid is in a text file. I have to read the text file for the process id and pass it as parameter to the kill command. Example $ cat prcid.txt 18650 I want to pass the value 18650 as a process id to kill command. $ kill -9 <value read from... (4 Replies)
Discussion started by: aksmuralee
4 Replies

10. Shell Programming and Scripting

pass arguments to called program

Thank you very much. (2 Replies)
Discussion started by: ShellUser
2 Replies
Login or Register to Ask a Question