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


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

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