Skip to main content
1 of 3
Stewart
  • 16.1k
  • 5
  • 49
  • 101

Looks like you are trying to remove foo from the file. Maybe this will work for you:

$ sed 's/foo//g' ./file bar bar 

What you are telling grep is:

  • Print foo for each instance, and
  • Print lines that don't have a foo

What you meant to tell grep was:

  • Print lines that don't match foo, or the parts of lines that don't include a foo

That can be reduced to:

  • Print every line, but remove foo from them

The two statements are pretty different. I think sed is a good solution for you and describes the reduced statement pretty well.

Stewart
  • 16.1k
  • 5
  • 49
  • 101