我想知道当结果从 diff 中产生时是否有办法在列的顶部打印文件名。目前我明白了;
diff -a --suppress-common-lines -y output_main.txt output_compare.txt
XXX Version X.X(X) | YYY Version Y.Y(Y)
ip address 10.10.88.50 255.255.255.254 | ip address 10.10.89.50 255.255.255.254
有用的是:
diff -a --suppress-common-lines -y output_main.txt output_compare.txt
output_main.txt output_compare.txt
======================== =======================
XXX Version X.X(X) | YYY Version Y.Y(Y)
ip address 10.10.88.50 255.255.255.254 | ip address 10.10.89.50 255.255.255.254
答案1
有一些与您要求类似的内容:
$ diff -c output_main.txt output_compare.txt
*** output_main.txt 2019-11-02 16:46:28.678377910 +0100
--- output_compare.txt 2019-11-02 16:46:27.770423548 +0100
***************
*** 1,2 ****
! XXX Version X.X(X)
! ip address 10.10.88.50 255.255.255.254
--- 1,2 ----
! YYY Version Y.Y(Y)
! ip address 10.10.89.50 255.255.255.254
答案2
这有点奇怪,但效果就像你想要的......
$ diff -a -y --suppress-common-lines <(echo output_main.txt; cat output_main.txt) <(echo output_compare.txt; cat output_compare.txt) | sed 2i=============================================================================
output_main.txt | output_compare.txt
===============================================================================
XXX Version X.X(X) | YYY Version Y.Y(Y)
ip address 10.10.88.50 255.255.255.254 | ip address 10.10.89.50 255.255.255.254
答案3
我会创建新函数:
mydiff(){
printf '%.30s%65s\n' "$1" "$2" "================" "===================";
command diff -y "$1" "$2"
}
该值65
来自以下事实:
'--side-by-side' ('-y') 选项选择并排格式。由于并排输出行包含两条输入行,因此输出比平常更宽:通常为 130 个打印列,可以适合传统的打印机行。
您可以通过选项更改列宽-W
。
输出:
$ mydiff output_main.txt output_compare.txt
output_main.txt output_compare.txt
================ ===================
XXX Version X.X(X) | YYY Version Y.Y(Y)
ip address 10.10.88.50 255.255.255.254 | ip address 10.10.89.50 255.255.255.254