[Tutor] Searching 2 Strings in A File

Alan Gauld alan.gauld at btinternet.com
Thu Jun 7 01:53:09 CEST 2012

On 06/06/12 20:33, dohoang4093 at comcast.net wrote:
> i am writing a python script that will be invoked as follows:

> cmd_line = Popen(["egrep", "(x,y)", aLogFile], stdout=PIPE, stdin=PIPE,
> stderr=STDOUT)

Assuming you really want to use egrep, why?
You could process the file directly in Python searching for your strings 
(using the re module if need be).

Using Popen makes sense if the command is doing a lot of work or is very 
CPU intensive. But for file processing its probably as easy to just use 
Python to scan the log files directly.

But if you are really doing something more complex I see that others 
have answered the Popen() question...

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list