syntax
sed '{[/]<n>|<string>|<regex>[/]}d' <fileName>
sed '{[/]<adr1>[,<adr2>][/]d' <fileName>
/.../=delimiters
n = line number
string = string found in in line
regex = regular expression corresponding to the searched pattern
addr = address of a line (number or pattern )
d = delete
examples
-
remove 3rd line
$ sed '3d' filename.txt
-
remove the line containning
awk
$ sed '/awk/d' filename.txt
-
remove the last line
$ sed '$d' filename.txt
-
remove all empty lines
$ sed '/^$/d' filename.txt $ sed '/./!d' filename.txt
-
remove the line matching by a regular expresstion
$ sed '/[0-9/][0-9]*$/d' filename.txt
-
remove lines between 7 and 9
$ sed '7,9d' filename.txt $ sed '/-start/,/-end/d' filename.txt
-
all above examples are only changed at the display of the file
-
permanent change
$ sed -i '2d' filename.txt # delete 2ed line and save to filename.txt $ sed -i".bak" '2d' filename.txt # backup filename.txt to filename.txt.bak # delete 2ed line and save to filename.txt