Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't print filenames in zgrep output when searching multiple files

Tags:

linux

grep

When I use zgrep to search multiple .gz files, the output contains the filename in it. Sometimes I don't need it bcz I use some other scripts to parse the output.

I tried using "-h" option but it doesn't seem to work with zgrep.

This is how I use the command:

admin@mybox [11:16:56]> zgrep -Eh "\.ERR|\.WARNING|\.FATAL" messages.?.gz
messages.1.gz:Oct 14 10:02:06 .............................................
messages.2.gz:Oct 14 09:27:58 .............................................

Any idea how I can stop the filename from being printed?

like image 766
gixxer Avatar asked Oct 14 '14 18:10

gixxer


1 Answers

-h does not work for zgrep, but the equivalent --no-filename option does. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=434429

EDIT As @ValarDohaeris suggests, the bug was apparently fixed in 1.6. I don't experience it in that version, while I still do in 1.5. I was not able to find such info in the changelog though.

like image 142
Mario Trucco Avatar answered Nov 15 '22 04:11

Mario Trucco