python grep

Mag Gam magawake at gmail.com
Thu Apr 8 07:21:11 EDT 2010


I am in the process of reading a zipped file which is about 6gb.

I would like to know if there is a command similar to grep in python
because I would like to emulate, -A -B option of GNU grep.

Lets say I have this,

083828.441,AA
093828.441,AA
094028.441,AA
094058.441,CC
094828.441,AA
103828.441,AA
123828.441,AA


if I do grep -A2 -B2 "CC"

I get 2 lines before and 2 lines after "C"

Is there an easy way to do this in python?

TIA



More information about the Python-list mailing list