csv search and print

Sergio Monteiro Basto sergio at sergiomb.no-ip.org
Mon Jun 18 22:53:49 CEST 2007


On Mon, 2007-06-18 at 13:11 -0700, John Machin wrote: 
> On Jun 19, 4:12 am, axja... at comcast.net wrote:
> > I have a csv file containing lot of rows & columns. I wanted to search thru the
> > heading for each column for a string and then print all the headings and the
> > corresponding rows if a match is found.
> >
> > Any advise?

you can put cvs in a MySql DB
mysql -e 'CREATE TABLE table2(col1 VARCHAR(255), col2 VARCHAR(255), col3
VARCHAR(255), col4 VARCHAR(255), col5 VARCHAR(255), col6 VARCHAR(255),
col7 VARCHAR(255), col8 VARCHAR(255), col9 VARCHAR(255), col10
VARCHAR(255), col11 VARCHAR(255), col12 VARCHAR(255), col13
VARCHAR(255), col14 VARCHAR(255))' table2

in mysql:
load data infile '/home/sergio/pesquisa/table2.txt' into table table2
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

and work with python and mysql 
http://dustman.net/andy/python/python-and-mysql

> 
> 1. Clarify your requirements: "corresponding rows" ... corresponding
> to what? How many rows/columns is a "lot"? "I have a csv file" ...
> only one? "search thru the heading for each column for a string" is
> open to misinterpretation of various kinds :-)
> 2. Write your script.
> 3. Ask a specific question if you have a problem.
> 
-- 
Sérgio M. B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2192 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20070618/ae502043/attachment.bin>


More information about the Python-list mailing list