Sometime on Nov 19, Sushant Gulati assembled some asciibets to say:
Can anybody suggest me how can i use the string in a
shell variable as a pattern in sed, grep and awk? And tell me if what i am expecting is
for sed and grep, just include your pattern in double quotes, and shell escaping will work.
foo='hello' cat myfile | sed -e "s/$foo/world/"
cat myfile | grep $foo cat myfile | grep "$foo world"
For awk, you can do the same, but I advise against it, since awk has its own variables. Instead, use the -v flag in awk to pass variables in.
awk -v bar=$foo '{print bar}'