pavement

Sed

From FreeBSDwiki
Revision as of 15:41, 29 September 2004 by Dave (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Short for "Streamline Editor", sed allows you to run a file through it and either match or change data without actually editing the file itself.

The most common usage is to change all instances of a phrase to another; to wit:

dave@samizdata:~% cat sed_testfile
 dave
 dave
 davedave
 jimbo
 dave
 freebsd
dave@samizdata:~% sed s/dave/david/ sed_testfile
 david
 david
 daviddave
 jimbo
 david
 freebsd
dave@samizdata:~% more sed_testfile
 dave
 dave
 davedave
 jimbo
 dave
 freebsd
dave@samizdata:~%

As you can see, the changes were not actually made to the file. I didn't tell it to put the changes anywhere! Easily fixed with the help of redirection:

dave@samizdata:~% sed s/dave/david/ sed_testfile > sed_testfile_new
dave@samizdata:~% more sed_testfile_new
 david
 david
 daviddave
 jimbo
 david
 freebsd
dave@samizdata:~%
Personal tools