## How do I highlight the differences between subsequent lines in a file?

I did a lot of emergency analysis for large log file analysis. This often requires tracing logs and looking for changes.

I longed for a solution to highlight these changes and make it easier for the eye to track.

I investigated the tools, but nothing seemed to meet my needs. I’ve written some rough scripts in Perl, but I want a more complete solution.

Can someone recommend a tool for this?

### Solution

# Edit the distance

Wikipedia:

The edit distance between two strings is the minimum number of operations required to convert one string to another, where the operation is to insert, delete, or replace a single character.

```
public static int LevenshteinDistance(char[] s1, char[] s2) {
int s1p = s1.length, s2p = s2.length;
int[][] num = new int[s1p + 1][s2p + 1];
fill arrays
for (int i = 0; i <= s1p; i++)
num[i][0] = i;
for (int i = 0; i <= s2p; i++)
num[0][i] = i;
for (int i = 1; i <= s1p; i++)
for (int j = 1; j <= s2p; j++)
num[i][j] = Math.min(Math.min(num[i - 1][j] + 1,
num[i][j - 1] + 1), num[i - 1][j - 1]
+ (s1[i - 1] == s2[j - 1] ? 0 : 1));
return num[s1p][s2p];
}
```

# Java sample application

String differences

The application uses the LCS algorithm to concatenate 2 text inputs into 1. The result will contain a minimal set of instructions to create a string for another string. Displays concatenated text below the command.

Download the app:

String Diff.jar

Download source:

Diff.java