Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass variable into script from command line 1

Status
Not open for further replies.
Apr 13, 2004
316
US
This solution from PHV worked great:

awk '/pag/{$1="";printf "%d)\t%s\n",++i,$0}' /path/to/input

I have been looking for an answer on the net, however, lacking any great skill with awk, how do I pass in "pag" as a variable? In ksh, of course, if I wanted to pass it from the command line I could do something like:

$0 variable

Which would pass variable into "pag" if it was $1, however that doesn't work in awk and I cannot find a way to do it.

Thanks!
 
awk -v pag=myVariableValue '$0 ~ pag {$1="";printf "%d)\t%s\n",++i,$0}' /path/to/input

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top