line numbers in shell

AKA ‘Today’s exciting shell command I learned’ nl

e.g.

$ echo -e "hello\ncruel\nworld" | nl
     1	hello
     2	cruel
     3	world

3 Comments

  1. Posted January 21, 2009 at 4:43 am | Permalink

    You don’t need a separate command just for that. ‘cat -n’ does the same thing.

  2. Edward
    Posted January 21, 2009 at 7:58 am | Permalink

    My actual invocation was more like:

    $ echo -e “hello\ncruel\nworld” | nl -v130 -nln -w1 -s ‘,’
    130,hello
    131,cruel
    132,world

    nl has more options for controlling the output

  3. steveo
    Posted February 4, 2009 at 11:51 pm | Permalink

    Not that it would have met your needs, but for fixing a compile problem in a terminal window when I know the line number for the compile error —
    One of the three vi commands I know is “go to line number”. To go to line 534:
    vi
    :534

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*