Line-end agnostic diff?

Brian Postow picture Brian Postow · Feb 12, 2009 · Viewed 15.8k times · Source

I'm working on a Mac, with some fairly old files. Different files were created by different programs, so some of them end with \r (Mac) and some with \n (Unix). I want to be able to run commands like diff, grep, etc. on these files, but the ones that have \r are treated as one giant line. Is there of a version of diff, grep, etc. that will work correctly with all new-lines?

ETA: I'd also like them to be Unix utilities, so I can use them in scripts, Emacs, etc...

Answer

Jay picture Jay · Feb 12, 2009

If you use diff -w it will ignore whitespace in the files, which is probably sufficient for your needs.

EDIT: just realized I misread the post the first time and you're actually looking for a diff that will work with \r line endings. My suggestion would be to convert the files with something like flip that can convert the files to a \n standard format.

EDIT 2: Just found something that looks like what you want - Diff'nPatch:

Diff'nPatch is a port to the Macintosh of the GNU 'diff', 'patch' and 'cmp' utilities. It lets you compare and find differences between two files or folders, collate two files, generate diffs in various formats (normal, context, unidiff, etc.), apply patches, compare files byte by byte. It can handle any type of line endings (mac, unix or windows)