in reply to Grep the second line from a file?

Not sure what exactly you mean by "grepping the 2nd line from a file", could you provide some sample input with expected output?

# 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

Replies are listed 'Best First'.
Re^2: Grep the second line from a file?
by graff (Chancellor) on Mar 20, 2014 at 03:31 UTC
    Depending on how large the input file(s) might be, it could be worthwhile to type just two more little words:
    perl -ne 'print and last if $.==2' -- FILENAME
Re^2: Grep the second line from a file?
by Anonymous Monk on Mar 19, 2014 at 23:47 UTC
    Many thanks, your first snippet of code is all I need :)