0

I'm programming intelligent diff in php. Which will be used for comparing two files whose content are configuration of router in two time period. As an output I need make colored highlighting of difference or if its on different place (line).

For example input one:

185.255.0.0/26 is subnetted, 1 subnets
172.16.0.0/16 is directly connected, Vlan 50

input two:

185.255.0.0/26 is subnetted, 15 subnets
172.16.0.0/16 is directly connected, Vlan 5

Now I can stupidly recognise if the lines are same or simmilar by computing matrix of levensthein distance. Can you advise me any other algorithm which could help mi with highligting differences? I probably need similar algorithms like are used in subversion or compare in total commander. Could you advise me where could I look?

dnagirl
  • 20,196
  • 13
  • 80
  • 123
user1097772
  • 3,499
  • 15
  • 59
  • 95

1 Answers1

1

Maybe not the most efficient way and pretty limited if actual lines are added or removed (you need some ways to detect that, there are multiple way to do that (see the link in the comment by Waleed Khan)).

But what if you first just checked the total string to see if it is different or not. If it is different you can split the total string (source and target) into tokens and compare the individual tokens. That way you can exactly tell (and highlight) what part of the total string is different.

ikku
  • 405
  • 3
  • 14