A Clockwork Orange A Clockwork Orange - 7 months ago 13
Bash Question

Delete lines in a text file that containing a specific string

How would I use to delete the whole line in a text file that contains a specific string?

Answer

To remove the line and print the output to standard out:

sed '/pattern to match/d' ./infile

To directly modify the file (and create a backup):

sed -i.bak '/pattern to match/d' ./infile
Comments