How can I ignore certain expressions from being compared using Difflib library

49 Views Asked by At

I want to create logic which will interact with the Difflib.ndiff() function that can compare text. Currently I want it to check text reports which show data from the test files. My problem stems from the Timestamps within the report

Text1 =
mm/dd/yyyy hh:mm:ss Report content shjsjsjsjdj
mm/dd/yyyy hh:mm:ss more Report to check content shjsjsjsjdj

Text2 mm/dd/yyyy hh:mm:ss same Report content to text1 shjsjsjsjdj mm/dd/yyyy hh:mm:ss more different Report to check content shjsjsjsjdj

Most lines will contain the time stamp. How can I make it so the ndiff() ignored when checking timestamps??

Tags returned by ndiff()
‘+’ belongs to text1
‘-‘ belongs to text2
‘ ‘ belongs to both

My current set up compares the two files only. The string containing the differences between us returned

1

There are 1 best solutions below

0
Alisson On

I am not sure if you are still needing this, since there's a while you have posted.

Im working on something here and I use ndiff to compare few files from time to time. what I would do is do a grep -v [word]. On the example on the image a ndiff from nmap files will always have the Nmap 7.94... so if I dont want it to show I just do: nmap [file1] [file2] | grep -v Nmap and it won't show the nmap. Depends on you data format you could just do an grep -v / and it will probably ignore all the / on the comparison. I hope I could help

ndiff from nmap