Results 1 to 3 of 3
Hi everybody,
some help is needed before I crash my head. I try to run a ksh script including:
echo $(awk -v var=$MyVariable -F '#' '$2 ~ /var/ {print var, ...
- 08-24-2009 #1Just Joined!
- Join Date
- Aug 2009
- Posts
- 2
awk using variable as pattern
Hi everybody,
some help is needed before I crash my head. I try to run a ksh script including:
echo $(awk -v var=$MyVariable -F '#' '$2 ~ /var/ {print var, $2 } $MyFile)
what I get is:
/var/ is constant "var" and not content of $MyVariable
but what I print with var is content of $MyVariable
any suggestion?
- 08-25-2009 #2Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Try replacing the awk line with
awk -v var=$MyVariable -F '#' '$2 ~ /var/ {print var, $2 } $MyFile
Code:awk -v var=$MyVariable -F '#' '$2 ~ /'$MyVariable'/ {print var, $2 }' $MyFile
- 08-25-2009 #3Just Joined!
- Join Date
- Aug 2009
- Posts
- 2
It works. Thanks a lot for your help.


Reply With Quote