Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: python grep

Reply
Thread Tools

Re: python grep

 
 
Mag Gam
Guest
Posts: n/a
 
      04-08-2010
Oh, thats nice to know!

But I use the CSV module with gzip module. Is it still possible to do
it with the subprocess?



On Thu, Apr 8, 2010 at 7:31 AM, Stefan Behnel <(E-Mail Removed)> wrote:
> Mag Gam, 08.04.2010 13:21:
>>
>> 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?

>
> Sure, just use a sliding window.
>
> However, for a 6BG file, you won't really like the performance. It's
> basically impossible to beat the speed of (f)grep.
>
> I'd use the subprocess module to run zfgrep over the file and parse the
> output in Python.
>
> Stefan
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression syntax the same in Python, Perl and grep? seberino@spawar.navy.mil Python 3 11-08-2007 12:09 AM
Grep Equivalent for Python tereglow Python 15 03-19-2007 03:33 PM
Efficient grep using Python? sf Python 15 12-17-2004 04:08 PM
Efficient grep using Python? Jane Austine Python 1 12-16-2004 04:54 AM
Python script to grep squid logs Zlatko Hristov Python 1 04-15-2004 03:15 PM



Advertisments