How to add line numbers to a text file?

Steven V. Christensen schriste at uceng.UC.EDU
Sat Dec 1 06:11:24 AEST 1990


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

>I need to add line numbers to a text file.

>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?

Under SunOS I would type:

	cat -n filename > wherever

Or under most any Unix:

	awk -e '{print NR, "  ",$0}' filename > wherever


	Happy hacking!

		Steven

>--
>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
-- 
Steven V. Christensen
U.C. College of Eng.
schriste at uceng.uc.edu
For the adventurous: svc at elf0.uucp



More information about the Comp.unix.questions mailing list