[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#810576: ITP: hail -- Efficiently extract arbitrary lines from a file or stream



I'm not objecting to this package, but for those who want achieve what
it does without having to depend on an extra package, I offer the
following.

On Sun, Jan 10, 2016 at 10:17:22AM +1100, Kevin Murray wrote:
> Hail gets its name from a contraction of head and tail, the common alternative
> to this program. It extracts lines from a file, taken on stdin, and prints them
> on stdout. It's so simple that the Unix wizards of old never bothered.

The README gives the following examples:

    # prints 1 through 10, i.e. does nothing
    seq 1 10 | hail 1-

    # prints 1 through 3, i.e. equivalent to `head -n 3`
    seq 1 10 | hail 1-3

    # prints 3 through 5, i.e. equivalent to `head -n 5 | tail -n 3`
    seq 1 10 | hail 3-5

    # prints 5 through 10, i.e. equivalent to `tail -n 6`
    seq 1 10 | hail 5-

    # prints 2, 3, 5 and 7, which is where I'll give up on my comparisons to
    # head and tail
    seq 1 10 | hail 2-3 5-5 7-7

These can be done with sed:

    seq 1 10 | sed -n '1,$p'
    seq 1 10 | sed -n '1,3p'
    seq 1 10 | sed -n '3,5p'
    seq 1 10 | sed -n '5,$p'
    seq 1 10 | sed -n '2,3p;5p;7p'

The syntax is not quite as easy, of course.

Happy hacking.

-- 
Schrödinger's backup hypothesis: the condition of any backup is
undefined until a restore is attempted. -- andrewsh

Attachment: signature.asc
Description: Digital signature


Reply to: