Hacker News new | ask | show | jobs
by yakubin 1287 days ago
I usually prefer to pipe fgrep -v into fgrep -v. With egrep you need to escape brackets and other characters.
3 comments

If you haven't seen it, there's been some noise recently about fgrep and its egrep friend

  $ fgrep -h
  fgrep: warning: fgrep is obsolescent; using grep -F
  $ egrep -h
  egrep: warning: egrep is obsolescent; using grep -E
True, for absolute fixed strings, the author's approach is superior.

Off the cuff, another way to do it is with awk's index function. I don't know what speed penalty this might impose.

  $ cat ~/fmgrep
  #!/bin/awk -f

  BEGIN { split(ARGV[1], s, ","); ARGV[1]="" }

  { m = 1; for(c in s) if(index($0, s[c])) m = 0; if(m) print }

  $ ~/fmgrep sshd,systemd,polkitd /var/log/secure
This also works:

fgrep -v -e THING1 -e THING2 -e THING3 -e THING4