diff ignore certain pattern in the file

落爺英雄遲暮 提交于 2019-12-13 03:29:11

问题


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.


回答1:


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

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.



来源:https://stackoverflow.com/questions/20048420/diff-ignore-certain-pattern-in-the-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!