4

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.

0

1 Answer 1

6

Simple. Be more specific.

sed -i "/\bexample\b/d" myfile
Sign up to request clarification or add additional context in comments.

2 Comments

how to delete a specific line with a string and also the line immediately above it?
@oortcloud_domicile Please search for similar questions; there are a ton. stackoverflow.com/questions/876446/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.