sed
sed is a stream editor utility which supports insertion, deletion, and search and replace of streams then prints the edited stream to standard output.
$ sed OPTIONS... [SCRIPT] [INPUTFILE...]
Useful Options / Examples
sed 's/FindWord/ReplaceWord/' filename > outfile
$ sed 's/Nick/Josh/' names.txt > out.txt
Changes first instances of ‘Nick’ in names.txt to ‘Josh’ and prints output to out.txt
sed 's/FindWord/ReplaceWord/g' filename > outfile
$ sed 's/Nick/Josh/g' names.txt > out.txt
Changes all instances of ‘Nick’ in names.txt to ‘Josh’ and prints output to out.txt
sed 'nd' filename
$ sed '5d' filename.txt
Deletes the 5th line from filename.txt
Options
| Option | Description |
|---|---|
| –help | Display a help message and exit. |
| –version | Output version information and exit. |
| -n –quiet –silent | Disables automatic printing. |
| -e script –expression=script | Add commands in script to set of commands to be run when processing input. |
| -f script-file –file=script-file | Add commands in script-file to set of commands to be run when processing input. |
| -i[SUFFIX] –in-place[=SUFFIX] | Specifies editing files in place. |
| -l N –line-length=N | Specifies line-wrap length (default = 70). |
| -posix | |
| -b –binary | Opens files in binary mode. |
| –follow-symlinks | Specifies that file passed in is a symbolic link. |
| -E -r –regexp-extended | Use extended regular expressions. |
| -s –separate | Consider files as separate streams. |
| –sandbox | Specifies that sed does not run any external programs. |
| -u –unbuffered | Buffer both input and output as minimally as practical. |
| -z –null-data –zero-terminated | Treat each line as null-terminated instead of newline-terminated. |