python vs. grep
Kam-Hung Soh
kamhung.soh at gmail.com
Mon May 12 19:53:42 EDT 2008
On Tue, 13 May 2008 00:03:08 +1000, Ricardo Aráoz <ricaraoz at gmail.com>
wrote:
> Ville Vainio wrote:
>> On May 8, 8:11 pm, Ricardo Aráoz <ricar... at gmail.com> wrote:
>>
>>> All these examples assume your regular expression will not span
>>> multiple
>>> lines, but this can easily be the case. How would you process the file
>>> with regular expressions that span multiple lines?
>> re.findall/ finditer, as I said earlier.
>>
>
> Hi, sorry took so long to answer. Too much work.
>
> findall/finditer do not address the issue, they merely find ALL the
> matches in a STRING. But if you keep reading the files a line at a time
> (as most examples given in this thread do) then you are STILL in trouble
> when a regular expression spans multiple lines.
> The easy/simple (too easy/simple?) way I see out of it is to read THE
> WHOLE file into memory and don't worry. But what if the file is too
> heavy? So I was wondering if there is any other way out of it. Does grep
> read the whole file into memory? Does it ONLY process a line at a time?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Standard grep can only match a line at a time. Are you thinking about
"sed", which has a sliding window?
See http://www.gnu.org/software/sed/manual/sed.html, Section 4.13
--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>
More information about the Python-list
mailing list