Sed

From wiki
Revision as of 17:33, 22 November 2018 by Hdridder (talk | contribs)
Jump to navigation Jump to search

Check the APO unix pages for more.

Tricks

sed 's/\r//' filename > newfilename
dos2unix substitute, remove all dos line endings.

Basics

sed 's/<old_string>/<new_string>/g' <file>
Substitute, no whitespace is allowed after the command (s), the first character following s is the fieldseperator./g substitutes all matching patterns in a line.
sed 's/pattern(with)sub(patterns)/\1 newpartofstring \2/' <file>
\1 and \2 refer to the subpatterns between brackets ().
sed '/<pattern>/d'
Delete matching line. !d negates the match => delete all lines not matching.