How to add line numbers to a text file?

terryl at sail.LABS.TEK.COM terryl at sail.LABS.TEK.COM
Sat Dec 1 10:03:48 AEST 1990


In article <rhoward.659993691 at romeo> rhoward at msd.gatech.edu (Robert L. Howard) writes:
+In <15248:Nov3018:01:4490 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
+
+>In article <6826 at uceng.UC.EDU> dmocsny at minerva.che.uc.edu (Daniel Mocsny) writes:
+>> 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?
+
+>grep -n .*
+
+Huh?  This is not even a complete answer....

     BUZZ!!! Thank you for playing, but you're wrong. According to man grep(1)

	-n Each line is preceded by its relative line number in the file.

Although Dan should have quoted the asterisk (tsk, tsk, tsk, Dan!!! (-:)

+Try:
+
+cat -n <infile >outfile
+
+(It's got to be faster than grep too)

     Maybe yes, maybe no. Most of the time spent in most *grep's is spent
generating the FSA for the pattern matching, not the actual pattern matching
itself.



More information about the Comp.unix.questions mailing list