Alex Rivera | Logout

Line-end agnostic diff?

Asked 2009-02-12T22:30:32.430
22

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. Are there versions 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...

Edit
Report

1 Answer

9

The diff utility bundled with OS X v10.7 (Lion) has an option 'strip-trailing-cr' that does that you want. You use it like so:

diff -cpt a.c b.c --strip-trailing-cr
answered 2011-10-10T13:07:07.837

Your Answer