A simple use of sed
May 26th, 2004
sed and awk are programs I usually get by without, but here's a handy use for sed.
Say you've got a file called johnbrown.txt containing the following text:
This file is the property of John Brown.
John Brown will be very annoyed if anyone alters it.
Signed: John Brown.
Run the following command:
sed -e s/John Brown/Jill Green/g johnbrown.txt > jillgreen.txt
You now have a new file containing the following:
This file is the property of Jill Green.
Jill Green will be very annoyed if anyone alters it.
Signed: Jill Green.
Not much use for a three-line file, but very handy for a 3000-line file.
Find out more about sed at:
http://pegasus.rutgers.edu/~elflord/unix/sed.html
If you want to do anything more complex than this (i.e. match whole words only, or match across multiple lines) then you can do it in sed, but it's painful. You're much better switching over to Windows and using Replace from Eluent Tools.
Potentially similar posts
- My first (useful) Ruby program – June 2011
- Mag+ video: How to sell an idea – September 2010
- Deleting those pesky lines in Microsoft Word – August 2010
- I love Emma Thompson – April 2010
- Madcap Flare 6 breaks PushOK SVN plugin – March 2010