PDA

View Full Version : pass variables to awk


yan
02-25-03, 09:47
how can I pass a variable to the awk with command line?
e.g.:

while read aline
do
val=$aline
awk '{ print $1, $val }' myfile
done < datafile

Thanks a lot for your help!

stevetucknott
02-25-03, 15:24
either with the -v option on the command line (see man awk) or by taking the variable outside the script ie:
1) ... awk -v v=$val1 '{print v}'....
OR
2) ... awk '{print "'$val1'"}'...

any help?