7 lines - Output only the given lines of the input stream
11 lines [I<RANGES> [I<RANGES> [...]]] [-- I<FILE> [I<FILE> [...]] | < I<FILE>]
15 Read from from I<FILE>s if specified, STDIN otherwise.
16 I<RANGES> is comma-delimited list of line numbers and inclusive ranges.
17 Special word "B<EOF>" in a range's upper limit represents the end of the file.
19 Starts the line numbering from 1.
21 If multiple files are given, restart the line numbering on each file.
23 Always displays the lines in the in-file order, not in arguments-order,
24 how they were given in I<RANGES> arguments; ie. does not buffer or seek in the input files.
25 So I<lines 1,2> and I<lines 2,1> both display the 1st line before the 2nd.
37 =item lines 2-4 6,8 10-EOF
43 Exit 2 if there was a range which was not found,
44 ie. a file had less lines than requested.
50 use List
::MoreUtils qw
/all any none/;
53 if(grep {$_ eq '--help'} @ARGV)
55 pod2usage
(-exitval
=>0, -verbose
=>99);
60 while(exists $ARGV[0])
67 for my $range (split /,/, $ARGV[0])
69 if($range =~ /^(\d+)(?:-(\d+|EOF))?$/)
71 push @ranges, {'from'=>$1, 'to'=>$2, 'found'=>1};
75 die "invalid range: $range\n";
82 eval 'use ARGV::readonly; 1' or die;
88 if($ARGV ne $prev_ARGV)
91 $status = 2 if any
{$_->{'found'} != 1} @ranges;
92 map {$_->{'found'} = 0} @ranges;
95 for my $range (@ranges)
97 my $from = $range->{'from'};
98 my $to = $range->{'to'};
101 if($. >= $from and ($to eq 'EOF' or $. <= $to)) { $range->{'found'} = 1; $include = 1; }
105 if($. == $from) { $range->{'found'} = 1; $include = 1; }
115 $status = 2 if any
{$_->{'found'} != 1} @ranges;