How to add line numbers to a text file?

Ralf Holighaus ralfi at pemstgt.PEM-Stuttgart.de
Sun Dec 2 23:54:00 AEST 1990


dmocsny at minerva.che.uc.edu (Daniel Mocsny) writes:

>I need to add line numbers to a text file. I am processing the text file
>from a Bourne shell script. I know that I can write a C program that
>reads each line of standard input with gets(), increments a line
>counter, and then prints the line counter and line to standard output.
>If I call the program number.c, then I can put a line in my shell
>script like:

>	number < $TEXTFILE > $NUMBEREDFILE

>I could also write a one-line awk script, but because I am much more
>familiar with C than awk, almost every time I try to do something simple
>in awk I wind up taking longer.

>My question to all of you, however, is this: faced with the need to
>number a text file from a shell script, how would you do it? I'm
>kind of curious to see the variety of approaches possible. Would you
>use C, awk, perl, sed, sh, cat, echo, expr, and/or dd?


>--
>Dan Mocsny				Snail:
>Internet: dmocsny at minerva.che.uc.edu	Dept. of Chemical Engng. M.L. 171
>	  dmocsny at uceng.uc.edu		University of Cincinnati
>513/751-6824 (home) 513/556-2007 (lab)	Cincinnati, Ohio 45221-0171

HOW ABOUT USING THE NL COMMAND AVAILABLE ON THE UNIX SYSTEM???

rgds
Ralf.
-- 
Programmentwicklung fuer    Microcomputer |         Ralf U. Holighaus
PO-Box 810165        Vaihinger Strasse 49 |         >> PEM Support <<
D-7000 Stuttgart 80          West Germany | holighaus at pemstgt.PEM-Stuttgart.de
VOICE: x49-711-713045 FAX: x49-721-713047 |      ..!unido!pemstgt!ralfi 



More information about the Comp.unix.questions mailing list