Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line-end agnostic diff?

Tags:

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

like image 856
Brian Postow Avatar asked Feb 12 '09 22:02

Brian Postow


1 Answers

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)

like image 184
Jay Avatar answered Sep 21 '22 07:09

Jay