Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Dec 2007 18:00:19 +0100
From:      "Danny Pansters" <danny@ricin.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: How to replace two strings in a file in the same time with sed command ?
Message-ID:  <200712111800.19674.danny@ricin.com>
In-Reply-To: <002801c83c11$cd434e70$dc96eed5@ihlasnetym>
References:  <002801c83c11$cd434e70$dc96eed5@ihlasnetym>

next in thread | previous in thread | raw e-mail | index | archive | help
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@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to
> "freebsd-questions-unsubscribe@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200712111800.19674.danny>