问题
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