How to diff oneline files

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2024-04-15

I was working with minified JS lately and needed to spot subtle differences in the output files. Using diff or grep didn't help much due to it outputting the whole file (i.e. the matching line)

git word diff

But git in --word-diff=porcelain mode does work

git diff --word-diff=porcelain 475.642648dbdbd6.js 475.beabb2f1add4.js

Note that the files need not be in git already. They can be anywhere on the file system.

pipe to fmt or fold then grep

cat x | fold -w 80 | grep needle or cat x| fmt -t | grep needle if you want more intelligent line breaks