I have a directory /backup/servers
in which I have file as below:
URF
VPF
XHF
And I have a another file /SUPPORT/data.txt
which is having content as below :
URF:Active:26-JAN-13
VPF:Active:26-JAN-13
XHF:Active:26-JAN-13
GSA:Active:26-JAN-13
HDKK:Active:26-JAN-13
I am listing /backup/servers
directory and writing into wmc.txt
file and want to match the content of this file to /SUPPORT/data.txt
file and print matching lines of /SUPPORT/data.txt
file.
For this, I have written the script below but this is not giving me any output. Can you please help me to get this accomplished.
#!/usr/local/bin/python2.7
import os
import re
DATA="/SUPPORT/data.txt"
path="/backup/servers"
fd = os.listdir(path)
p = r'wmc.txt'
p1 = r'wmc1.txt'
fh = open(p, 'w+')
for i in fd[-15:]:
if re.search("(.*)-MC(.*)",i):
rslt=i.replace("-MC","")
fh.write(rslt)
fh.write("\n")
fl=open(DATA,'r')
for line1 in fl:
for line2 in fh:
if re.match("(.*)line2(.*)",line1):
print line1
fh.close()
fl.close()
Current Code:
path="/backup/servers"
DATA="SUPPORT/data.txt"
fd=os.listdir(path)
for i in fd[-15:]:
if re.match("(.*)-MC(.*)",i):
rslt=i.replace("-MC","")
fh=open("wmc.txt",'w+')
fh.write(rslt)
fl=open(DATA,'r')
for line1 in fl:
fh.seek(0,0)
for line2 in fh:
if re.search(".*%s.*"%(line2),line1):
#if re.search(line2,line1):
print line1
break