Re: python grep

Discussion in 'Python' started by Mag Gam, Apr 8, 2010.

  1. Mag Gam

    Mag Gam Guest

    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 <> 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
    >
     
    Mag Gam, Apr 8, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zlatko Hristov

    Python script to grep squid logs

    Zlatko Hristov, Apr 14, 2004, in forum: Python
    Replies:
    1
    Views:
    880
    Lee Harr
    Apr 15, 2004
  2. sf
    Replies:
    15
    Views:
    794
    Christos TZOTZIOY Georgiou
    Dec 17, 2004
  3. Jane Austine

    Efficient grep using Python?

    Jane Austine, Dec 16, 2004, in forum: Python
    Replies:
    1
    Views:
    592
    Tim Peters
    Dec 16, 2004
  4. tereglow

    Grep Equivalent for Python

    tereglow, Mar 14, 2007, in forum: Python
    Replies:
    15
    Views:
    26,557
    tereglow
    Mar 19, 2007
  5. Replies:
    3
    Views:
    388
    BartlebyScrivener
    Nov 8, 2007
Loading...

Share This Page