SED - Stream Editor
Grammar
command
: [address[,address]]function[arguments]
address
: [0-9]... || $ || /regex/
function
: todo
-E
: used extended regular expressions
-n
: suppress stdout (by default each line of input is streams to stdout after applying functions)
-i
: edit the input file in place. optionally add an extension if you want to back up the original file.
Examples
Notation
Effect
8d
Delete 8th line of input.
/^$/d
Delete all blank lines.
1,/^$/d
Delete from beginning of input up to, and including first blank line.
/Jones/p
Print only lines containing "Jones" (with -n option).
s/Windows/Linux/
Substitute "Linux" for first instance of "Windows" found in each input line.
s/BSOD/stability/g
Substitute "stability" for every instance of "BSOD" found in each input line.
s/ *$//
Delete all spaces at the end of every line.
s/00*/0/g
Compress all consecutive sequences of zeroes into a single zero.
`echo "Working on it."
sed -e q'1i How far are you along?'`
Prints "How far are you along?" as first line, "Working on it" as second.
5i 'Linux is great.' file.txt
Inserts 'Linux is great.' at line 5 of the file file.txt.
/GUI/d
Delete all lines containing "GUI".
s/GUI//g
Delete all instances of "GUI", leaving the remainder of each line intact.
Last updated
Was this helpful?