2009-10-19

Sed Tips

In sed, if a pattern can be included inside of single quotes, no variable will be extented. Exmple 1 and 2. In order to use value of a variable, the pattern need to be included by double quotes and use "#" instead of "/" for seperator. See example 3 and 4.
  1. sed -i 's/\[filename\]/myfile/g' ${file}.new------>succ.
  2. sed -i 's/\[filename\]/$file/g' ${file}.new------->variable is not extended.
  3. sed -i "s/\[filename\]/$file/g" ${file}.new------->fails( Unknown option to 's')
  4. sed -i "s#\[filename\]#$file#g" ${file}.new-------->succ.

No comments:

Post a Comment