in reply to extract (a range of) numbered lines from a file
I ended with a wonderful (;=)) one if you accept to pass range à la Perl 1,2,4..5 instead of hyphenated ones like 1,2,4-5
I'm very proud of the solution to workaround the off by one error between line number (from 1) and array elements (from zero): a two char fix 0, was enough.
For the joy of many, another evil use of eval (warning: win32 doublequotes!)
perl -e "BEGIN{$w=pop @ARGV}print +(0,<ARGV>)[eval $w]" linenumb +er.txt 1,3..5
L*
PS even simpler:
perl -e "print +(0,<ARGV>)[eval pop]" linenumber.txt 1,3..5
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: extract (a range of) numbered lines from a file -- smarter oneliner 22chars
by shmem (Chancellor) on Sep 21, 2016 at 16:31 UTC | |
by Discipulus (Canon) on Sep 21, 2016 at 20:27 UTC |