sed
ShellAdvanced In simulator In real LinuxStream editor: transform text with rules
Name: sed = stream editor
You can practise it right away in the simulator, and use it in real Linux mode too.
Description
sed reads input line by line, edits it with the commands in a script and prints the result. The most used command is substitution s/pattern/replacement/flags; others include d (delete), p (print), i (insert) and a (append), each optionally limited to line numbers or regex matches.
By default sed only prints and leaves files alone; -i edits in place, so preview without it first.
Syntax
sed [OPTION]... 'SCRIPT' [FILE]...Common options
| s/old/new/ | Replace the first old on each line with new |
| s/old/new/g | Replace every old on each line |
| /re/d | Delete lines matching re; or by number: 3d deletes line 3 |
| N,Mp | Print lines N to M (with -n: sed -n 10,20p) |
| -n / --quiet / --silent | Don't print by default; use with the p command |
| -i / --in-place | Edit files in place |
| -e / --expression SCRIPT | Add a script; may be repeated |
| -E / -r / --regexp-extended | Extended regular expressions (+ ? | ( ) without backslashes) |
| -f / --file FILE | Read the sed script from FILE |