Hi Siva,

A few comments before going further:
a. You should have continued in the same thread as before (changing the subject line, if necessary), nobody would've minded. People not interested would've ignored the thread.

b. If you did want to start a new thread (since this one is not really about gawk), you should repeat the context (ie: restate the original problem). By not doing so, you've confused the people who weren't interested in gwak but are interested in python.

c. I noticed you asked the same question on python-list. Nothing wrong with that per se. ...however, you are unlikely to get too many (relevant) responses there because the people there who are not on ILUGC and have not read the gawk thread have no context information !(*)

Anyways, that said, here is something that might help. Assuming the file you pasted in the last thread:
[st...@laptop ~]$ cat Report_2_5
C_ID, ID_NO, stat1, vol2, amount3
2134, Ins1, 10000, 20000, 10
2112, Ins3, 30000, 20000, 10
2121, Ins3, 30000, 20000, 10
2145, Ins2, 15000, 10000, 5
2245, Ins2, 15000, 10000, 5
0987, Ins1, 10000, 20000, 10
[st...@laptop ~]$ cat cids
Ins1
Ins3

here, are some basic operations using the csv module for you to try out:
>>> r25 = csv.reader(open('Report_2_5'))
>>> cids = [ line.strip() for line in open('cids') ]
>>> cids
['Ins1', 'Ins3']
>>> for row in r25:
...     if row and (row[1].strip() in cids):
...             print row
...

and in case you prefer DictReader ...

>>> r25 = csv.DictReader(open('Report_2_5'))
>>> r25.fieldnames
['C_ID', ' ID_NO', ' stat1', ' vol2', ' amount3']
>>> for row in r25:
...     for key, val in row.items():
...             print val
...
......
......
>>> r25 = csv.DictReader(open('Report_2_5'))
>>> d = {}
>>> for row in r25:
...     d[r25.line_num] = [ val.strip() for val in row.values() ]
...
>>> print d

(*) I composed the mail earlier today but had to cut short due to some work, when i returned to it I noticed that you had sent out another mail with context ...and see ? ...you got some very good responses.

..and oh, btw, using sql also is a good idea:
http://code.activestate.com/recipes/498130/
http://docs.python.org/library/sqlite3.html

hth,
cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
_______________________________________________
To unsubscribe, email [email protected] with "unsubscribe <password> <address>" in the subject or body of the message. http://www.ae.iitm.ac.in/mailman/listinfo/ilugc

Reply via email to