Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 ?

>Solution :

  • 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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading