The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

linerange - Retrieve line ranges from a filehandle

VERSION

This document describes version 0.001 of linerange (from Perl distribution App-linerange), released on 2019-03-17.

SYNOPSIS

 % linerange [OPTION]... <RANGESPEC> [FILE]...

Examples:

 # get line 25 from FILE
 % linerange 15 < FILE

 # get second to second last lines from process output
 % some-process | linerange 2..-2

DESCRIPTION

Retriving line range(s) from text is one of those things that are not easy enough to do using standard Unix toolbox. To retrieve lines 5-12 from FILE, you either use head and tail:

 % head -12 FILE | tail -8

requiring you to remember what -n means for head and tail as well as calculate 12-5+1. You can use sed or awk or perl:

 % sed -n '5,12p' FILE
 % awk 'NR >= 5 && NR <= 12' FILE
 % perl -ne'print if $. >= 5 && $. <= 12' FILE

which is fine only if you are familiar with those programming languages. And they require you to type too many symbols.

linerange offers you a dead-simple alternative:

 % linerange 5-12 FILE
 % linerange 5..12 FILE

as well as some features like allowing single line numbers:

 % linerange 10 FILE

multiple line ranges:

 % linerange 5-12,20,25-32 FILE

as well as negative line numbers:

 % linerange 5..-1 FILE
 % linerange -5..-1 FILE
 % linerange 5..-3 FILE

You can use .. or - (they both work), you don't have to worry about getting the lower range and higher range mixed up (they both work), you don't have to worry about intersecting ranges (duplicates will be removed).

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/App-linerange.

SOURCE

Source repository is at https://github.com/perlancar/perl-App-linerange.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-linerange

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

head, tail, sed, awk, perl

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.