Difference between revisions of "Sed"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
Line 1: Line 1:
sed: Replace strings
+
[[sed]] is a [[command]] to edit a text stream in [http://en.wikipedia.org/wiki/Batch_mode batch mode].
 +
 
 +
For example,
 +
sed "s/a/o/"
 +
Will read your input (stream) from the keyboard and '''s'''ubstitute every '''a''' by an '''o'''.
 +
 
 +
= Usecases =
 +
* Remove leading white space
 +
sed 's/^[ \t]*//'
 +
* Replace strings
 
  sed -e "s/cgi?\([0-9][0-9]*\)/cgi@\1.html/g" myfile.html > index.html
 
  sed -e "s/cgi?\([0-9][0-9]*\)/cgi@\1.html/g" myfile.html > index.html
  

Revision as of 09:37, 10 May 2009

sed is a command to edit a text stream in batch mode.

For example,

sed "s/a/o/"

Will read your input (stream) from the keyboard and substitute every a by an o.

Usecases

  • Remove leading white space
sed 's/^[ \t]*//'
  • Replace strings
sed -e "s/cgi?\([0-9][0-9]*\)/cgi@\1.html/g" myfile.html > index.html

See also