in reply to How does $. work in one liner?
In your example, you don't need the $_. This will print lines 1 and 2 from the file test.txt:
If you prefer to be more explicit:perl -ne 'print if 1..2' test.txt
perl -ne 'print if $. >= 1 && $. <= 2' test.txt
This type of question comes up often enough that I keep a list of one-liner references.
Update: See also:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How does $. work in one liner?
by afoken (Chancellor) on May 29, 2016 at 08:51 UTC |