I'm logging in to my company's IBM AIX system and the grep there isn't GNU and it's the default one and it doesn't support the options -B, -A, -C. I found this workaround for normal grep:
grep -n '123456' file.debugz.gz |
cut -d':' -f1 |
xargs -n1 -I % awk 'NR<=%+3 && NR>=%-2' file.debugz.gz
However I'm trying to use zgrep or zegrep to get the values from inside a .debug.gz file which has a lot of data in it and big file size, so instead of gunzip and searching manually in each .debug.gz file I want to use the above command but it doesn't work with zgrep or zegrep.
I want to show a context of 30 lines above and below the matching line.
Please note that I cannot gunzip the file, I want to grep what's inside without any scripts or gunzip.
You could use awk to emulate the unsupported
-A/-Boptions (-Cseems like a shortcut for specifying both).For example:
Optionally, keep track of when to print
--divisions.Sample usage:
You still need a way for awk to access the decompressed data.
gunzip -ccan write to stdout/pipe without unpacking the original file.So you could do something like: