[Tutor] Possible to search text file for multiple string values at once?

Scott Stueben sidewalking at gmail.com
Fri Jan 23 19:25:02 CET 2009

Hi all,

I understand that python excels at text processing, and wondered if
there is a way to use python to accomplish a certain task.  I am
trying to search large text files for multiple strings (like employee
ID number, or name).  Any text editor (I use Windows mostly) will
certainly have a "find", "replace", or even "find in files" (to search
multiple files for a value) function, but this is searching for one
string at a time.

I would like to search a text file for a list of strings, like a sql query.

For instance:  To search a text file for the values 'Bob', 'John',
'Joe', 'Jim', and 'Fred', you would have to open the dialog and do
five separate searches.  Lots of copying and pasting, lots of room for

But if you were in a SQL database, you could do something like:

"SELECT * FROM my_table WHERE first_name IN ('Bob', 'John', 'Joe',
'Jim', 'Fred')"

and you would get results for all five values.

I would love to set up a script to parse a file and show results from
a list of strings.  Is this possible with python?

Thanks for the input and help,

More information about the Tutor mailing list