You're replying to a comment by CKP.

CKP Permalink
April 28, 2014, 14:30

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

# cat myfile
Hello World
Hello Universe
# echo $VAR

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


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


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

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

Thanks in advance

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "halflife3_100": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.