好吧,我认为最简单的解决方案是从第一个文件中过滤掉这些行。例如,您可以使用以下 awk 脚本执行此操作:
# if line contains 'Directory created', just skip it.
/Directory created/ {
had_dir = ""
next
}
# if line contains sole 'Directory', store it and lookup next line.
/Directory/ {
had_dir = $0
next
}
# if line contains sole 'created' and we stored a line (which means
# it contained 'Directory'), then delete the stored one and skip
# (effectively, skip both).
/created/ && had_dir {
had_dir = ""
next
}
# otherwise, if we stored a line, print it.
had_dir {
print had_dir
had_dir = ""
}
# and print the current line.
{
print
}
如果您的输入更复杂,您可能需要稍微调整一下正则表达式。
然后,使用脚本过滤掉第一个文件:
$ awk -f script.awk file1 | diff - file2
0a1
> INFO : reuse temp1
请注意,您将-
作为第一个参数传递给diff
, 以使其读取管道输出awk
而不是文件。
还要注意,线偏移将不再正确。