• numlines

    From porkchop@porkchop@invalid.foo (Mike Sanders) to comp.lang.awk on Tue Nov 14 03:23:32 2023
    From Newsgroup: comp.lang.awk

    FILE: example1.txt

    001 Simple little script to number lines
    002 (this block of text demonstrates its use).
    003

    FILE: example2.txt

    001 Yes I know, there are other utilities that do the same,
    002 but when in Rome, do as the Romans do...
    003

    # tags: numlines, lines, numbers, pad, awk, code
    #
    # adds uniformly padded line numbers to output to a width
    # of three zeros (999 max per file - adjust as needed)
    # Michael Sanders 2023
    # https://busybox.neocities.org/notes/numlines.txt
    #
    # usage: awk -f numlines.txt FILE [FILE]
    #
    # example output...
    #
    # FILE: fubar.sh
    #
    # 001 #!/bin/sh
    # ...
    # 999 exit $?

    FNR == 1 { printf "\nFILE: %s\n\n", FILENAME }

    { printf "%03d %s\n", FNR, $0 }

    # eof
    --
    :wq
    Mike Sanders

    --- Synchronet 3.20a-Linux NewsLink 1.114