stringshellsedline

delete line containing a specific string in shell


I want to delete a line containing a specific string from my file. I do it like that:

sed -i "/example/d" myfile

But my file contains many lines containing strings that contain the string that I want to delete. for example my file contains lines as bellow and I want to delete only the first line that contains "example":

myfile:
 example
 example1
 example2
 ..

My question is how to do if want to delete only the line that contains exactly my string "example" and keep the other ones.


Solution

  • Simple. Be more specific.

    sed -i "/\bexample\b/d" myfile