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.
Advertisement
Answer
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’.