hello everybody, 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 really possible or not?
Anyways, thanks a lot to Vinayak and Dinesh for replying to my small and trivial matters. I hope someday, I'll be able to help others in these matters rather than just askin questions, since i am a loyal member of the linux community, with a strong belief in Linux, although I am still at the periphery of this vast forest.
Warm regards,
Sushant
__________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com
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}'
On Saturday 19 November 2005 08:58 PM, Sushant Gulati wrote:
hello everybody, 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 really possible or not?
Go through below link...... Very quick guide to Sed with example.
http://www.tldp.org/LDP/abs/html/x17375.html#AEN17393
Sushant
--Hardik Dalwadi.