How to replace two strings in a file in the same time with sed command ?

Danny Pansters danny at ricin.com
Tue Dec 11 14:26:20 PST 2007


On Tuesday 11 December 2007 17:20:50 Halid Faith wrote:
> I want to replace two or more strings in a file in the same time with sed
> command. How do I that ?
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe at freebsd.org"

just use -e s/foo/bar/ as many times as needed.

e.g.

%cat afile
foo1 foo3 foo2 foo7
%sed -e s/foo1/bar1/ -e s/foo2/bar2/ -e s/foo3/bar3/ -i .bak afile
%cat afile.bak
foo1 foo3 foo2 foo7
%cat afile
bar1 bar3 bar2 foo7

Dan


More information about the freebsd-questions mailing list