The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pass parameter into script alfredo Shell Programming and Scripting 2 04-08-2008 06:40 PM
how can i pass parameter with spaces to csh script umen Shell Programming and Scripting 1 03-19-2008 08:33 AM
Help required to pass the parameter u263066 Shell Programming and Scripting 4 08-11-2006 10:56 AM
Pass Parameter to Another Script rvprod UNIX for Dummies Questions & Answers 4 04-05-2002 09:07 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-14-2004
Registered User
 

Join Date: Mar 2004
Posts: 6
Stumble this Post!
Question PASS parameter to AWK

Hi,

Can i pass a parameter(not a file name) as a parameter to a awk program?

eg;

$awk -f test 1 2 3

here test is the filename...and 1,2,3 are the i/p parameters?

thank you:-)
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-14-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Stumble this Post!
Parameters passed to AWK are stored in the ARGV array, which has ARGC elements.

Example: suppose foo.awk contains
Code:
BEGIN {
   for ( i = 0; i < ARGC; i++ )
   {
       print ARGV[i]
   }
}
Then executing
Code:
awk -f foo.awk 1 2 3
would print
Code:
awk
1
2
3
ARGV[0] is the awk command itself, and the other ARGV elements are the parameters passed.

Peace,
ZB
http://www.zazzybob.com
Reply With Quote
  #3 (permalink)  
Old 05-14-2004
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Stumble this Post!
You can also assign variables on the command line, e.g....

awk -v a=1 -v b=2 -v c=3 -f test.awk

The -v option means that the variables are assigned before the BEGIN section.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0