Path: utzoo!attcan!uunet!kddlab!trl!rdmei!ptimtc!olivea!samsung!uakari.primate.wisc.edu!dali.cs.montana.edu!ogicse!zephyr.ens.tek.com!tekchips!tekgvs!sail!terryl From: terryl@sail.LABS.TEK.COM Newsgroups: comp.unix.questions Subject: Re: How to add line numbers to a text file? Message-ID: <8518@tekgvs.LABS.TEK.COM> Date: 30 Nov 90 23:03:48 GMT References: <6826@uceng.UC.EDU> <15248:Nov3018:01:4490@kramden.acf.nyu.edu> Sender: news@tekgvs.LABS.TEK.COM Reply-To: terryl@sail.LABS.TEK.COM Organization: Tektronix, Inc., Beaverton, OR. Lines: 28 In article rhoward@msd.gatech.edu (Robert L. Howard) writes: +In <15248:Nov3018:01:4490@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: + +>In article <6826@uceng.UC.EDU> dmocsny@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 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.