by matvore · 2y ago · 0 comments
<access.log sed -n '/mail/p; 500q' | perl -e ...
If perl is processing the file line-by-line then filtering lines by regex and stopping at line X is trivial, and you don't even need sed.I have heard snarky Perl putdowns ad nauseam at work and on HN and may have regretted using it a handful of times but I can say worse or similar for other popular tools, languages...
awk '/mail/ && NR <= 500 {...}' access.log
If you want N matched lines: awk '/mail/ && i < 500 {i++; ...}' access.log