Can I grep only the first n lines of a file?

David LeBauer picture David LeBauer · Jan 6, 2012 · Viewed 181.5k times · Source

I have very long log files, is it possible to ask grep to only search the first 10 lines?

Answer

Joachim Isaksson picture Joachim Isaksson · Jan 6, 2012

The magic of pipes;

head -10 log.txt | grep <whatever>