I have two separate scripts currently, One that formats a single document and one that compares two formatted documents to look for differences. I'm trying to combine the two so it's more efficient. Any help is greatly appreciated.
To format the code within a document:
f1 = open("test4", "r")
f1_line = f1.readline()
line_no = 1
# Loop if either file1 or file2 has not reached EOF
while f1_line != '':
for line in f1:
if "001A" in line: print ((line))
if "##!!STF" in line: print((line))
#Increment line counter
line_no += 1
f1.close()
Here is part of the next code that compares two formatted documents for differences:
# Ask the user to enter the names of files to compare
fname1 = input("Enter the first filename: ")
fname2 = input("Enter the second filename: ")
# Open file for reading in text mode (default mode)
f1 = open(fname1)
f2 = open(fname2)
# Print confirmation
print("-----------------------------------")
print("Comparing files ", " > " + fname1, " < " +fname2, sep='\n')
print("-----------------------------------")
# Read the first line from the files
f1_line = f1.readline()
f2_line = f2.readline()
# Initialize counter for line number
line_no = 1
# Loop if either file1 or file2 has not reached EOF
while f1_line != '' or f2_line != '':
# Strip the leading whitespaces
f1_line = f1_line.rstrip()
f2_line = f2_line.rstrip()
a_string = f1_line
substr1 = a_string[17:23]
b_string = f2_line
substr2 = b_string[17:23]
if substr1 !=substr2:
print("Line-%d" % line_no,f1_line, f2_line)
# Print a blank line
print()
What I'm trying to figure out is how to combine both scripts together to ask the user to enter two unformatted documents, format them, compare and find differences between the two documents then display the results.