I have a master file which contains certain text- let's say-
file contains x
the image is of x type
the user is admin
the address is x
and then there 200 other text files containing texts like-
file contains xyz
the image if of abc type
the user is admin
the address if pqrs
I need to match these files up. The result will be true if the files contains the text exactly as is in the master file, with x being different for each file i.e. 'x' in the master can be anything in the other files and the result will be true.What I have come up with is
arr=master.split('\n')
for file in files:
a=[]
file1=file.split('\n')
i=0
for line in arr:
line_list=line.split()
indx=line_list.index('x')
line_list1=line_list[:indx]+line_list[indx+1:]
st1=' '.join(line_list1)
file1_list=file1[i].split()
file1_list1=file1_list[:indx]+file1_list[indx+1:]
st2=' '.join(file1_list1)
if st1!=st2:
a.append(line)
i+=1
which is highly inefficient. Is there a way that I can sort of map the files with master file and generate the differences in some other file?
I know this is not really a solution, but you can check if the file is in the same format by doing somwthing like:
by checking the rest of the lines
"file contains"
"the user is"
"the address is"
you will be able to somewhat validade if the file you are checking is valid
You can check this link to read more about this "substring idea"