Link to home
Start Free TrialLog in
Avatar of neil_mw
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
Avatar of griessh
griessh
Flag of United States of America image

Hi neil_mw, did you try

export VAR=XXX

... ($2==$VAR) ...

======
Werner
Avatar of neil_mw
neil_mw

ASKER

Yes I did, I'm afraid
ASKER CERTIFIED SOLUTION
Avatar of geotiger
geotiger

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of neil_mw

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial