linerange - Retrieve line ranges from text


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


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


 # get line 25 from FILE
 % linerange 15 < FILE

 # get lines from 2nd to last (a.k.a. everything but the first) from process output
 % some-process | linerange 2..-1

 # get some lines from ls output
 % ls | linerange 1,2-10,20


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
 % linerange 5+7 FILE   ;# equivalent to 5..(5+7) = 5..12

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).


Please visit the project's homepage at


Source repository is at


Please report any bugs or feature requests on the bugtracker website

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.


head, tail, sed, awk, perl


perlancar <>


This software is copyright (c) 2019 by

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