Pythonic Script That Ignores Timestamps In Log Files
There are 2 log files : log A and log B. log A 2015-07-12 08:50:33,904 [Collection-3]INFO app -Executing Scheduled job: System: choppa1 2015-07-12 09:56:45,060 [Collection-3] INF
Solution 1:
I would change pat = re.compile("^[^0-9]")
to pat = re.compile("\d{4}-d{2}-d{2}
and also it is better to open files
withopen(filename) as f:
this way python will close file for you, no need for close(f) statement.
Solution 2:
Here is the small script to eliminate timestamp from the beginning of the file.
program = open("log1.txt", "r")
program_contents = program.readlines()
program.close()
program = open("log2.txt", "r")
program_contents1 = program.readlines()
program.close()
for i in range(0,len(program_contents1)):
if program_contents[i] == '\n':
continueif program_contents[i][19:] == program_contents1[i][19:]:
print("Matches")
Post a Comment for "Pythonic Script That Ignores Timestamps In Log Files"