Difference between revisions of "Sed"
From Linuxintro
imported>ThorstenStaerk (sed -i '1i <This is now at the first line>' <filename>) |
imported>ThorstenStaerk |
||
Line 12: | Line 12: | ||
* Insert a line a beginning of file | * Insert a line a beginning of file | ||
sed -i '1i <This is now at the first line>' <filename> | sed -i '1i <This is now at the first line>' <filename> | ||
+ | * Replace several newlines by one | ||
+ | sed 's/\ \{1,\}/\ /g' | ||
= See also = | = See also = |
Revision as of 12:16, 22 December 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
- Insert a line a beginning of file
sed -i '1i <This is now at the first line>' <filename>
- Replace several newlines by one
sed 's/\ \{1,\}/\ /g'