For Programmers: Free Programming Magazines  


Home > Archive > AWK > April 2007 > Substition









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Substition
manzur1986@gmail.com

2007-04-04, 6:57 pm

Hi!

How can I make awk to substitute variable in regular expression. For
instance,
What should I do to get this
awk '{$1 ~ /smth/ { print $2 }}' somefile
from
awk var='smth' '{$1 ~ /var/ { print $2 }}' somefile

Vassilis

2007-04-04, 6:57 pm


=CF/=C7 manzur1986@gmail.com =DD=E3=F1=E1=F8=E5:
> Hi!
>
> How can I make awk to substitute variable in regular expression. For
> instance,
> What should I do to get this
> awk '{$1 ~ /smth/ { print $2 }}' somefile
> from
> awk var=3D'smth' '{$1 ~ /var/ { print $2 }}' somefile



You probably want

awk -v var=3D'smth' '$1 ~ var { print $2 }' somefile

If this is not what you mean, please specify.

Vassilis

manzur1986@gmail.com

2007-04-06, 6:57 pm

Yes, Thanks a lot

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com