Sed: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| 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. | ||
;<code>sed -i 'commands' filename</code> | |||
:Edit the file directly (inplace) by default the result is sent to standard output | |||
=Basics= | =Basics= | ||
Revision as of 19:25, 13 October 2019
Check the APO unix pages for more.
Tricks
sed 's/\r//' filename > newfilename- dos2unix substitute, remove all dos line endings.
sed -i 'commands' filename- Edit the file directly (inplace) by default the result is sent to standard output
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.