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?


4 Answers 4


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
  • 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, 2015 at 10:53
  • 1
    You can avoid the temporary files by the following bash-ism (not sure about compatibility with other shells): meld <(tr -s ' ' '\n' < file1.txt) <(tr -s ' ' '\n' < file2.txt) Dec 21, 2020 at 9:48

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.

  • 2
    FYI, xxdiff segfaults if the lines are longer than 32768 chars... Jul 18, 2017 at 13:02

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.)


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .