Re: sed tee, “Search, replace, and commit back.”


Earlier, I described a way to replace all occurrences of a particular pattern with another in a file and write the change(s) back into that file. BBBart on #linuxpakistan on irc.freenode.net suggested another way of doing it that does not involve calling another process. It uses the “-i” switch to sed(1), something I did not know of owing to the particular manpage for sed(1) on my system not documenting it. Here’s the alternative:

ayaz$ sed -i bak 's/pattern/replace/g' file

Note, however, that I have GNU sed version 3.02 installed and it doesn’t recognise the “-i” switch. I guess this funtionality is introduced in latter versions of sed.

Advertisements

One thought on “Re: sed tee, “Search, replace, and commit back.”

  1. Pingback: Perl’s “Search, replace, and commit back” « Libel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s