Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Mar 262009

How to replace multiple strings using sed?


If you have multiple strings to replace, you can either using the "-e" option in sed, e.g.

sed -e 's/a/A/' -e 's/b/B/' < old.txt > new.txt

or, you can use a sed script file to store all the replace conditions

e.g. vi replace.sed


and execute like

sed -f replace.sed < old.txt > new.txt

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>