Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- file1 = "file1.txt"
- file2 = "file2.txt"
- outputfile = "file3.txt"
- f1lines = []
- f2stripped = []
- f2linesoriginal = []
- output = []
- with open(file1, "r") as f1:
- for line in f1:
- f1lines.append(line.strip())
- with open(file2, "r") as f2:
- for line in f2:
- f2linesoriginal.append(line)
- compdata = line.split(";")[-2:] #removing the [ag] in start of line.....
- datastring = ""
- for element in compdata:
- datastring += element.strip() + ";" #putting the string back toghether adding ";"
- f2stripped.append(datastring[:-1])
- for line in f1lines:
- if line in f2stripped:
- output.append(f2linesoriginal[f2stripped.index(line)].strip()) #if match add the original f2 line
- else:
- output.append(line) # else keep the f1 line
- print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement