What is the simplest way to extract from a file a line given by its number. E.g., I want the 666th line of somefile
. How would you do this in your terminal, or in a shell script?
I can see solutions like head -n 666 somefile | tail -n 1
, or even the half-incorrect cat -n somefile | grep -F 666
, but there must be something nicer, faster, and more robust. Maybe using a more obscure unix command/utility?
awk 'NR==666
but that, while shorter, is significantly slower. – terdon Sep 09 '15 at 14:37