neil_mw
asked on
Evaluating environment variables in awk
Hi,
Just a hopefully easy question:
I've got an awk command on a single line namely:
awk -F: '/^[^#]/ {if ($2 == "XXX") printf "%s\n", $1}' /tmp/file.txt
Everything works perfectly, however I need to replace the "XXX" with an environment variable. Unfortunately, I can't get this to work. Please help!
Thanks,
Neil
Just a hopefully easy question:
I've got an awk command on a single line namely:
awk -F: '/^[^#]/ {if ($2 == "XXX") printf "%s\n", $1}' /tmp/file.txt
Everything works perfectly, however I need to replace the "XXX" with an environment variable. Unfortunately, I can't get this to work. Please help!
Thanks,
Neil
ASKER
Yes I did, I'm afraid
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Unfortunately we don't have nawk installed and, as this is a customer machine, we'd have a fight before being able to install it!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
export VAR=XXX
... ($2==$VAR) ...
======
Werner