awkgrepzgrep

ZGrep for first occurence of pattern *after* given line


so I know that to find the line number of the first occurrence of a pattern in a file I do:

zgrep -n -m 1 "pattern" big_file.txt.gz

but what If I want to skip the first 500K lines? (I can't decompress the file. It's too large.)


Solution

  • You may use this gzcat | awk command:

    gzcat big_file.txt.gz |
    awk 'NR > 500000 && /pattern/ {print NR ":" $0; exit}'