Friday, December 24, 2010

Passing variables to sed

Using "sed" in command line is fine. We may not make much mistakes in the syntax.
Normally, we use single quotes around sed which works well.

Code:
root@bt> sed 's/genius/dump/g' infile

But if you want to use/pass variables to sed, you will need to use double quotes.

Code:
root@bt> var=genius
root@bt> sed "s/$var/dump/g" infile

Got it? Good!

Have a nice day!