[NTLUG:Discuss] A quick script anyone?
Carl Haddick
sysmail at glade.net
Thu Jul 31 16:08:32 CDT 2008
On Thu, Jul 31, 2008 at 11:29:04AM -0500, Eric Waguespack wrote:
> On Thu, Jul 31, 2008 at 10:37 AM, Daniel Hauck <daniel at yacg.com> wrote:
>
> > Parsing a CSV file and generating some output.
> >
> > I have a list where the first field is a number and the next two are
> > text fields. A line would look like this:
> >
> > 10, "US", "United States of America"
> >
> > I just need to be able to parse this line to fill some variables. The
> > output part I have down pretty well and will be able to transform this
> > file (once I get the line parsing part down) into the output desired.
> >
> > It might be helpful to know that I will need to discard the quote
> > characters and just need the text within.
> >
Awk will be your shortest solution, I imagine, but here's a crack at it
in Python, one of my personal favorites.
#!/usr/local/bin/python
import csv
for i in csv.reader(file('infile')):
print 'The %s, (%s) is ranked number %s worldwide.'%(i[1],i[0],i[0])
And now, for something completely different...
Carl
More information about the Discuss
mailing list