How to use a value of a variable in awk? Something like this:
filename = "test.txt"
ls -l | awk '{ if ($9 == filename) print("File exists")}'
I can't use $ in awk to access the value of that variable.
How to use a value of a variable in awk? Something like this:
filename = "test.txt"
ls -l | awk '{ if ($9 == filename) print("File exists")}'
I can't use $ in awk to access the value of that variable.
Here's the syntax to pass variables (and a few awk-style issues fixed):
awk -v filename="${filename}" '$9 == filename { print "File exists" }'