Difference between revisions of "Sed"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
− | Check the [https://unix.antiperfect.org/scripting/sed/ APO unix pages] | + | Check the [https://unix.antiperfect.org/scripting/sed/ APO unix pages] for more. |
=Tricks= | =Tricks= | ||
Line 5: | Line 5: | ||
;<code>sed 's/\r//' filename > newfilename</code> | ;<code>sed 's/\r//' filename > newfilename</code> | ||
:dos2unix substitute, remove all dos line endings. | :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. |
Revision as of 17:33, 22 November 2018
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.