i am trying to grab some lines form lines in a huge file. For example suppose
f =
a b
c d
e s
m n
h g
.
.
.
The code I am trying to used is as follows
import re
f = open('f.txt')
y = [a,s, ...] # the laters that i would like to grab it with the line form the file f
grab = y
for line in f:
match = grab.search(line)
if match:
print match.group()
With the following code you will print lines from
fif any of the chars inyis in the line.You can modify it easily if what you want is to get lines where both chars are in
ybtw, do not forget to close your open file or better to use
with as.