in reply to Printing a line only if first line of file

perl -ne "$. ==1 and print;" filename.txt
perl -e "print scalar <>;" filename.txt
perl -ne "print and last;" filename.txt
perl -ne "last; END{print}" filename.txt
perl -ne "die $_;" filename.txt
perl -pe "$. > 1 and last;" filename.txt

Some will be more efficient than others.

The point is that if all you need to print is the first line, you should probably terminate reading the file once you've read the first line.


Dave

Replies are listed 'Best First'.
Re^2: Printing a line only if first line of file
by jwkrahn (Abbot) on Feb 01, 2008 at 13:31 UTC
    perl -ne 'print && close ARGV' filename.txt
A reply falls below the community's threshold of quality. You may see it by logging in.