The diff output with file path is too long. I will like to remove the path for readable with diff built-in parameter/option without via shell script ?
$ 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
However, The path is too long for me. I want to get shortly path like as
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
It's hard to answer your question because diff
utility does not exist in Linux (the kernel). It exists in GNU , and it exists in Unix , because those are operating systems. Linux is a kernel, usually packaged with GNU and distributed as GNU/Linux .
With this being said, if you are using GNU diff
(from GNU diffutils
), then you can use the --label LABEL
option (twice) to specify the alternate names you wish to see printed in place of the file names.
In your example:
$ 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
If you're stuck with POSIX diff
, then I'd say your best option is to rewrite that header with sed
or awk
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.