lines/getline: Replacement for head/tail

When I create a Shell script and try to do this in a POSIX compatible way, sometimes I would need to read (only) certain lines of a file or a pipe.

In order not to end up in a construction of head an tail invokations and in order to output several blocks of data at one time I programmed a replacement for head and tail.

The first version was a slow shell skript, the second version is a faster awk program which has same functionality.


Programs' usage is explained inthe following examples:

Remark: Only use the program in a private scope; for further information please look at the imprint of this website.


Verwendung (Linux, BSD, Windows (cygwin), OS X (?)):
  1. Herunterladen: Version 1.07 oder Version 1.08 (Bug behoben)
  2. In ein neues/leeres Verzeichnis (!) entpacken (Unpack into an empty dir!)
  3. Das neue Verzeichnis in PATH aufnehmen
  4. Ausführen:
    # printf "    %s\n" a b c d e f g | getline 2-3,3#-6
        b
        c
        e
        f
    # printf "    %s\n" a b c d e f g | getline 3#-6,2-3
        b
        c
        e
        f
    # printf "    %s\n" a b c d e | lines 2-3,3#-4
        b
        c
        c
        d
    # printf "    %s\n" a b c d e | lines --unique 2-3,3#-4
        b
        c
        d
    # printf "    %s\n" a b c d e | lines --unique 2-3,3#-
        b
        c
        d
        e
    #
    
    
  5. An der neu gefundenen Alternative zu head und tail freuen!

Document of May 2015, last modification on 7 January 2024. Page source

Hintergrundbild: Schräge Vorderansicht der Lok 1142.562-9