使用相对路径前缀的Linux差异比较工具输出

3

文件路径导致的 diff 输出过长。我想通过 diff 内置的参数/选项来去除路径,以便更易读,而不需要使用 shell 脚本

$ diff -u /share/a/b/c/d /share/1/2/3/4/             <== path is too long
diff -u /share/a/b/c/d/dirsave /share/1/2/3/4/dirsave
--- /share/a/b/c/d/dirsave      2017-08-11 16:21:50.100547799 +0800
+++ /share/1/2/3/4/dirsave      2017-08-11 16:22:21.612546684 +0800
@@ -1,2 +1,3 @@
 pushd /share/qca6174/qca6174a-5-pci/QCA6174A-5-PCI/fixce/AIO/rootfs-ra-r105.build/lib/firmware
 pushd /share/qca6174/qca6174a-5-pci/QCA6174A-5-PCI
+libc

然而,这条路径对我来说太长了。 我希望能够获得一个简短的路径,就像这样:

diff -u dirsave dirsave                                <== enhance shortly path
--- dirsave     2017-08-11 16:21:50.100547799 +0800
+++ dirsave     2017-08-11 16:22:21.612546684 +0800
@@ -1,2 +1,3 @@
 pushd /share/qca6174/qca6174a-5-pci/QCA6174A-5-PCI/fixce/AIO/rootfs-ra-r105.build/lib/firmware
 pushd /share/qca6174/qca6174a-5-pci/QCA6174A-5-PCI
+libc
1个回答

1
由于(内核)Linux中不存在 diff 工具,因此很难回答您的问题。它存在于GNUUnix中,因为它们是操作系统。Linux是一个内核,通常与GNU捆绑在一起,并作为GNU/Linux分发。
话虽如此,如果您使用GNU diff(来自GNU diffutils),则可以使用--label LABEL选项(两次)指定要在文件名位置打印的替代名称。
在您的示例中:
$ diff -u --label file1 --label file2 /share/a/b/c/d /share/1/2/3/4/             
--- file1
+++ file2
@@ -1,2 +1,3 @@
 pushd /share/qca6174/qca6174a-5-pci/QCA6174A-5-PCI/fixce/AIO/rootfs-ra-r105.build/lib/firmware
 pushd /share/qca6174/qca6174a-5-pci/QCA6174A-5-PCI
+libc

如果你卡在了 POSIX diff 上,那么我会建议你用 sedawk 重新编写该标题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接