I'm trying to use awk with a user-defined variable ($EVENT
, where $EVENT
is a filename and also a column in a textfile) in the if condition, but it doesn't seem to recognize the variable. I've tried with various combinations of ', ", { and ( but nothing seem to work.
EVENT=19971010_1516.txt
awk '{if ($2=="$EVENT") print $3,$4,$8}' FILENAME.txt > output.txt
It is possible to use user-defined variables in awk
commands? If so, how does the syntax work?
you cannot use
$FOO
directly in your code, because awk will think it is columnFOO
. (FOO is variable). but your FOO is empty. to use shell var, use-v
like: