线端不可知差异? [英] Line-end agnostic diff?
问题描述
我正在Mac上工作,其中包含一些相当旧的文件.不同的文件是由不同的程序创建的,因此其中一些以\ r(Mac)结尾,而某些以\ n(Unix)结尾.我希望能够在这些文件上运行diff,grep等命令,但是具有\ r的命令被视为一条巨大的线.是否有 diff ,
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:我也希望它们成为Unix实用程序,因此我可以在脚本,Emacs等中使用它们.
ETA: I'd also like them to be Unix utilities, so I can use them in scripts, Emacs, etc...
推荐答案
正如Jay所说,Diff'nPatch似乎是您想要的东西.另外,您也可以在单个命令中将所有以'\ n'结尾的'\ r'行尾转换为单个命令,如下所示:
As Jay said, Diff'nPatch seems what you are looking for. Alternatively you can convert all your '\r' line endings in '\n' in a single command like this:
sed -ie 's/\r/\n/' filename
或
find . | xargs -n1 sed -ie 's/\r/\n/'
(在后一种情况下,您可能希望以某种方式过滤文件列表,否则它将应用于所有子目录中的所有文件.)
(You may want to filter the list of files in some way in the latter case or it will be applied to all the files in all subdirectories.)
这篇关于线端不可知差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!