# prints only the second line of the file perl -ne 'print if $.==2' -- FILENAME # prints only the second line of the file if it matches a pattern perl -ne 'print if $.==2 && /pattern/' -- FILENAME