You are viewing this site in a simplified layout because your browser does not yet support CSS Subgrid.

op111.net

Search op111.net

How to remove file lines that match a pattern

Using GNU sed:

$ sed -i '/pattern/d' ./file

To remove the lines and keep a copy of the original:

$ sed -i.bak '/pattern/d' ./file

Since the pattern is a regular expression, special regex characters should be escaped. For example, to remove all lines containing example.com:

$ sed -i '/example\.com/d' ./file

Documentation