sed

Delete command

Delete one line containing a pattern

Given a file file.txt with the following content:

line 1
line 2
line 3

You can delete a line from file content with the d command.

The pattern to match is surrounded with default / delimiter and the d command follows the pattern:

sed '/line 2/d' file.txt

The above command will output:

line 1
line 3

To edit the file in place, use the -i option:

sed -i '/line 2/d' file.txt

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow