0

I'm interested in figuring out a way to delete an entire line in a text file that contains a particular string. This will be for a text file that operates like a phone book containing names, address, phone numbers, etc

[Ex]

John Smith, 123 Fake St, 555-555-555

I want to know how I can search for a particular name and remove the entire line that contains it. So for the example above, I would search for "John" or "Smith" or "John Smith" and remove the entire line that contains those words.

Would I used grep, or sed for this? I want it to make a permanent change to the file

2
  • I hope that was a joke....
    – Justin
    Dec 13, 2014 at 18:31
  • it was not. and you should not post someone else's data so I was warning
    – Alex Jones
    Dec 13, 2014 at 18:37

1 Answer 1

1

You could use d command from sed.

To remove all lines containing word John, you would do

sed --in-place /John/d ./file

In case of Multiple criterions, use the -e command

sed --in-place -e '/John/d; /John Smith/d' ./file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .