Help needed with awk
I am trying to extract information from a file using awk
e.g. My file Code:
10001 aaa111 bbb222 Code:
awk '/10001/ { print $1 " " $2 " " $3 }' myfile.txt But if I want to hard code it and pass in the 10001 as a parameter into the script or using a variable... Code:
Is there something wrong with it? I can't figure out why. |
You have to put $mycode outside single quotes, otherwise it is not processed by the shell:
Code:
awk '/'$mycode'/ { print $1 " " $2 " " $3 }' myfile.txt |
The '$' sign which u r actually using has a different meaning in awk. I think, the site mentioned below would assist u in solving the problem.
http://www.vectorsite.net/tsawk_2.html#m2 Bye & Good Luck |
thanks!
|
The $mycode variable in post #2 is evaluated by the shell before the arguments are filled out.
Code:
set awk '/'$mycode'/ { print $1 " " $2 " " $3 }' myfile.txt |
All times are GMT -5. The time now is 06:36 PM. |