git diff --word-diff --no-index -- foo bar
or
git diff -U0 --word-diff --no-index -- foo bar
You can run this command even if the files are not part of a git repository.
Ref:- https://unix.stackexchange.com/a/330807/198064
Related commands:
git diff --no-index --color-words -- foo bar
- to diff word by word
git diff --no-index --color-words=. -- foo bar
- to diff character by character
To diff headers of two files without creating any temporary files
% diff <(head -n 1 foo.20170102) <(head -n 1 foo.20170104)
diff --strip-trailing-cr file1 file2