Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!sdd.hp.com!elroy.jpl.nasa.gov!ncar!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.questions Subject: Re: How to add line numbers to a text file? Message-ID: <18438:Nov3021:25:2590@kramden.acf.nyu.edu> Date: 30 Nov 90 21:25:25 GMT References: <6826@uceng.UC.EDU> <15248:Nov3018:01:4490@kramden.acf.nyu.edu> Organization: IR Lines: 22 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? > >grep -n .* > Huh? This is not even a complete answer.... Of course it is. Whatever your shell is, you want to exec grep with arguments -n and .*. Of course, in most shells you'll have to quote the asterisk. By assumption, the input is a text file. Why is more information necessary? > cat -n outfile > (It's got to be faster than grep too) Possibly, but I find its output format more difficult to use directly as input to other programs. (Yeah, that's it: echo 'set nu' >> ~/.exinit. :-) ) ---Dan