Skip to main content
Post Closed as "Duplicate" by tripleee sed
deleted 1 character in body
Source Link
Penny Liu
  • 17.9k
  • 5
  • 89
  • 109

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.

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.

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.

removed deprecated tag [delete] as part of a slow burninate
Source Link

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.

Thanks.

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.

Thanks.

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.

Source Link
user1027336
  • 117
  • 1
  • 3
  • 11

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.

Thanks.