Scripting Question

Chris Mohler cr33dog at gmail.com
Sat Feb 14 02:41:59 UTC 2009


On Sat, Feb 14, 2009 at 8:18 PM, Patton Echols <p.echols at comcast.net> wrote:
> I have a fairly massive flat file, comma delimited, that I want to
> extract info from.  Specifically, I want to extract the first and last
> name and email addresses for those who have them to a new file with just
> that info. (The windows database program that this comes from simply
> will not do it)  I can grep the file for the @ symbol to at least
> exclude the lines without an email address (or the @ symbol in the notes
> field)  But if I can figure this out, I can also adapt what I learn for
> the next time.  Can anyone point me in the right direction for my "light
> reading?"

Maybe this will help (a good start anyway):
#===========================
#!/usr/bin/env python

import csv

# Open CSV of ZIP code data
file = open("your filename here", 'r')
csv = csv.reader(file)
	
for row in csv:
    do something....
#=======================

if you replace "do something" with "print row[0[", it will print the
first column, "print row[1]" the second column - you get the idea ;)

If you get an error about csv - check that the python-csv package is
installed...

Chris




More information about the ubuntu-users mailing list