October 14th, 2013, 01:34 AM
Searching for a list of strings in a file with Python
I'm trying to search for several strings, which I have in a .txt file line by line, on another file.
So the idea is, take input.txt and search for each line in that file in another file, let's call it rules.txt.
So far, I've been able to do this, to search for individual strings:
How can I change this to input the strings to be searched from another file?
shakes = open("output.csv", "r")
for line in shakes:
if re.match("STRING", line):
So far I haven't been able to.
Thanks for the ideas.
October 14th, 2013, 01:57 AM
Use this program instead.
[/code] are essential for python code and Makefiles!
October 25th, 2013, 04:59 PM
patterns = open("input.txt")
lines = open("rules.txt")
for pattern in patterns:
for line in lines:
if re.match(pattern, line):
There ya go!