Identical Identical - 1 year ago 96
Bash Question

Word count after zgrep

I'm a little confused as to what this counts:

zgrep -B 4 "xyz" <filename> | grep -i abcd | wc -l

Does it count the occurences of abcd in the 4 lines xyz? "wc -l" returns a different count than the number of lines present inside the file.

Answer Source

Prints every 'xyz' and 4 lines before from the file.

zgrep -B 4 "xyz" <filename>

Prints only lines, containing (case-insensitive) 'abcd'.

grep -i abcd

Counts the lines.

wc -l

All in all, it shows how many case-insensitive 'abcd' line can be find in file being withing 4 lines before 'xyz'.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download