How to Delete a Line Containing Specific String using SED

Channel: Linux
Abstract: sed -i ‘/Text to Delete/d’ /path/to/file SED is an Stream Editor having capability to remove lines from file having specific string. Using -i with sed
Syntax: sed -i ‘/Text to Delete/d’ /path/to/file

SED is an Stream Editor having capability to remove lines from file having specific string. Using -i with sed we can remove line in same file.

Example 1:

Remove all lines from /var/log/messages having string 「DELETE THIS TEXT」 and restore output in new file. Do not make any changes in original line.

$ sed "/DELETE THIS TEXT/d" /var/log/messages > messages.txt
Example 2:

Remove all lines from /var/log/messages having string 「DELETE THIS TEXT」 in same file.

$ sed -i "/DELETE THIS TEXT/d" /var/log/messages

Ref From: tecadmin

Related articles