Segfault
Segfault

Reputation: 65

Multi line invert grep match using file

I am trying to visualise all new sockets created after a save point in Debian Linux 5.14:

ss -a > state
ss -a | grep -v -f state

Expected output : Nothing

Observed output : The same as ss -a

I checked the content of the file and every line does properly end with a $ indicating it's multine.

Can't truely grasp why this happens, did anyone encounter this before ?

Upvotes: 0

Views: 60

Answers (1)

John Kugelman
John Kugelman

Reputation: 361710

  • Use -F so the lines are treated as fixed strings and not regexes. This ensures that items like * and [::ffff:127.0.0.1] are not treated as wildcards and character classes.
  • For good measure, use -x to match whole lines.
$ ss -a > state
$ wc -l < state
1867
$ ss -a | grep -vxFf state | wc -l
56

Upvotes: 1

Related Questions