26

I have a file that has only one line. Its size is about 20,000 bytes.

The file has been modified, and I wanted to know where.

I thought using diff, but it shows me the complete line, because it outputs the line that has the difference - but in this case it's the only line in the file that has differences.

So I wanted to see what is the difference.

Any advice?

14

Assuming that there are many whitespaces, as in normal text, you can split the file by words and compare it with a normal diff tool, for example, meld:

tr -s ' ' '\n' < file1.txt > file1.txt.split
tr -s ' ' '\n' < file2.txt > file2.txt.split
meld file1.txt.split file2.txt.split
| improve this answer | |
  • 2
    Seems to be the most straightforward solution for me. The diff problem in itself is trivial, however most tools (not just diff-tools) can't manage long lines, so the problem is dealing w/ long lines rather, not the diffing itself. – p1100i Feb 24 '15 at 10:53
4

I'd find a diff that does intra-line diffs. I use xxdiff on UNIX. I think WinMerge does intra-line diff on Windows.

The other answers are good as well: wdiff, or breaking into chunks - the chunk boundaries are easier to define if the data is delimited by say a pipe or a comma.

| improve this answer | |
3

If this is a one-time problem, I'd create copies of the files with \n characters inserted every 50 characters, then diff those copies. (I chose 50 because it makes the math easy going from differing line number to byte offset in the original files but might adjust that up/down based on what I found.)

| improve this answer | |
0

I found git diff and the --word-diff=porcelain option helpful for such a task, for example given 2 files with long lines that only differ by 1 character, the output can be piped via grep to filter the changed lines and changes, and then via grep again to only show the last 80 characters of each line:

echo {1..4000} A {4001..8000} > a.tmp
echo {1..4000} B {4001..8000} > b.tmp

> git diff -U0 --word-diff=porcelain a.tmp b.tmp | grep -A3 '@@' | egrep -o '.{1,80}$'
@@ -1 +1 @@
3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000
-A
+B
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.