Shell variable must within single-quotes in awk command, just like '$A'
e.g. File fruit.txt content as follow
apple 99
orange 25
lemon 30
FRUIT=apple, To get number after $FRUIT
awk '/'$FRUIT'/ {print $2}' fruit.txt (Rignt)
awk '/$FRUIT/ {print $2}' fruit.txt (Wrong, not work)
Leave a comment