sed
Excerpt from man page
Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sedβs ability to filter text in a pipeline which particularly distinguishes it from other types of editors.
Things to keep in mind π
sed
uses special characters differently from the shell so wrap the script part in single quotes- More info about said can be found on the man page
man sed
- Full manual using
info sed
The full documentation for sed is maintained as a Texinfo manual. If the info and sed programs
are properly installed at your site, the command
info sed
should give you access to the complete manual.
Examples π
Simple word replace π
-i
- Says to edit the file instead of sending output to stdouts
- At start is for substitutiong
- At end says to replace all not just first per line- If both
-i
andsource_file.txt
are left out it will read the βfileβ from stdin and output to stdout
sed -i 's/original_word/replacement_word/g' source_file.txt