Looking for a Python Program/Tool That Will Add Line Numbers to atxt File

Reedick, Andrew jr9445 at ATT.COM
Mon Feb 18 10:22:03 EST 2008


> -----Original Message-----
> From: python-list-bounces+jr9445=att.com at python.org [mailto:python-
> list-bounces+jr9445=att.com at python.org] On Behalf Of William Pursell
> Sent: Monday, February 18, 2008 8:37 AM
> To: python-list at python.org
> Subject: Re: Looking for a Python Program/Tool That Will Add Line
> Numbers to atxt File
> 
> On Feb 14, 6:54 am, "W. Watson" <wolf_tra... at invalid.com> wrote:
> > See Subject. It's a simple txt file, each line is a Python stmt, but
> I need
> > up to four digits added to each line with a space between the number
> field
> > and the text. Perhaps someone has already done this or there's a
> source on
> > the web for it. I'm not yet into files with Python. A sudden need
has
> burst
> > upon me. I'm using Win XP.
> 
> Not sure if "Python program/tool" means "a tool or a program
> in Python", but if awk is okay, that's the tool I would use:
> 
> awk '{printf( "%4d %s\n", NR % 10000, $0 )}'


On a related note, since it's probably easier to install Perl instead of
awk on a windows box:

type foo.java | perl -ne "$counter++; print sprintf(qq(%4d ), $counter),
$_;"





More information about the Python-list mailing list