diff忽略文件中的某些模式 [英] diff ignore certain pattern in the file

查看:145
本文介绍了diff忽略文件中的某些模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个文件之间进行区分,其中包含以 line_ $ NR开头的行。我想在文件之间进行区分,以抽象出 lines_ $ NR的存在,但是在打印差异时,我希望显示lines_ $ NR。
可以这样做吗?
谢谢。

I want to make diff between two files which contains lines beginning with "line_$NR". I want to make diff between the files making abstraction of the presence of "lines_$NR" but when the differences are printed I want lines_$NR to be displayed. It is possible to do that? Thanks.

推荐答案

我相信在这种情况下,您必须预处理iput文件才能删除 / ^ line_ [0-9] * / ,比较生成的文件,然后根据差异输出中的行号将差异输出与删除的单词重新组合。

I believe in this case, you have to preprocess your iput files to remove /^line_[0-9]*/, diff the resulting files, then recombine the diff output with the removed words according to line numbers in diff output.

Python的 difflib 在这里应该非常方便,或者与perl相同。如果您想坚持使用shell,我想您可以使用awk。

Python's difflib should be very handy here, or same from perl. If you want to stick to shell, I suppose you could get by with awk.

如果不需要精确的输出,也许可以使用diff的-line-format = ... 指令将实际行号注入差异中,而不是在预处理步骤中删除的单词。

If you don't need exact output, perhaps you can use diff's --line-format=... directive to inject actual line number in a diff, rather than the word you removed in preprocessing step.

这篇关于diff忽略文件中的某些模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆