Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Pattern matchin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 14 Topic 2115 of 2317
Post > Topic >>

Pattern matching a Shell variable inside awk!!

by fazlin <fazlincse@[EMAIL PROTECTED] > Dec 26, 2007 at 06:12 AM

Hello All,

I have an input file "myfile" and a shell variable "VAR" whose
contents are shown below:

# cat myfile
Hello World
Hello Universe
# echo $VAR
World

I need to process all lines in "myfile" which contains pattern "World"
using awk. It works if i do as shown below:

# awk '/World/ { print $0 }' myfile

But i could not use VAR to do the same operation. I tried the
following even knowing that these will not work:

# awk '/$VAR/ { print $0 }' myfile

and

# awk -v lvar=$VAR '/lvar/ { print $0 }' myfile

and

# awk -v lvar=$VAR 'lvar { print $0 }' myfile

Please let me know how to match the contents of VAR in awk.

Thanks in advance,
Fazlin
 




 14 Posts in Topic:
Pattern matching a Shell variable inside awk!!
fazlin <fazlincse@[EMA  2007-12-26 06:12:22 
Re: Pattern matching a Shell variable inside awk!!
Janis Papanagnou <Jani  2007-12-26 16:15:52 
Re: Pattern matching a Shell variable inside awk!!
fazlin <fazlincse@[EMA  2007-12-26 09:26:07 
Re: Pattern matching a Shell variable inside awk!!
Janis Papanagnou <Jani  2007-12-26 19:20:53 
Re: Pattern matching a Shell variable inside awk!!
fazlin <fazlincse@[EMA  2007-12-26 12:46:42 
Re: Pattern matching a Shell variable inside awk!!
Grant <g_r_a_n_t_@[EMA  2007-12-27 07:54:50 
Re: Pattern matching a Shell variable inside awk!!
gazelle@[EMAIL PROTECTED]  2007-12-26 21:36:48 
Re: Pattern matching a Shell variable inside awk!!
Ed Morton <morton@[EMA  2007-12-26 16:18:02 
Re: Pattern matching a Shell variable inside awk!!
Grant <g_r_a_n_t_@[EMA  2007-12-27 10:05:25 
Re: Pattern matching a Shell variable inside awk!!
Ed Morton <morton@[EMA  2007-12-26 23:52:10 
Re: Pattern matching a Shell variable inside awk!!
Grant <g_r_a_n_t_@[EMA  2007-12-28 08:00:25 
Re: Pattern matching a Shell variable inside awk!!
Ed Morton <morton@[EMA  2007-12-27 17:57:59 
Re: Pattern matching a Shell variable inside awk!!
Grant <g_r_a_n_t_@[EMA  2007-12-28 12:54:06 
Re: Pattern matching a Shell variable inside awk!!
Ed Morton <morton@[EMA  2008-01-02 09:50:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 2:26:38 CDT 2008.