我正在尝试比较两个文件的差异,这两个文件是更新前后的软件包列表,并以易于阅读的形式显示它。
基本上我的一些内容是这样的:
更新前:
2:tar-1.23-13.el6.x86_64/
tcp_wrappers-libs-7.6-57.el6.x86_64/
14:tcpdump-4.0.0-5.20090921gitdf3cb4.2.el6.x86_64/
3:traceroute-2.0.14-2.el6.x86_64/
更新后:
2:tar-1.23-15.el6_8.x86_64/
tcp_wrappers-libs-7.6-57.el6.x86_64/
14:tcpdump-4.0.0-5.20090921gitdf3cb4.2.el6.x86_64/
3:traceroute-2.0.14-2.el6.x86_64/
samba-common-3.6.23-43.el6_9.x86_64/
samba-winbind-clients-3.6.23-43.el6_9.x86_64/
samba-winbind-3.6.23-43.el6_9.x86_64/
预期输出:
Pre-Update | Postupdate
2:tar-1.23-13.el6.x86_64/ | 2:tar-1.23-15.el6_8.x86_64/
(empty) | samba-common-3.6.23-43.el6_9.x86_64/
(empty) | samba-winbind-clients-3.6.23-43.el6_9.x86_64/
(empty) | samba-winbind-3.6.23-43.el6_9.x86_64/
基本上显示两个文件下的更新以及仅在新文件下的添加内容。
我不介意其他显示它的方式,只要它格式良好,例如 oldpackagename --> newpackagename 或沿该路线的其他内容。
最佳答案
如果您想要良好的并排输出,您可以使用:
$ diff -y --suppress-common-lines file1.txt file2.txt
示例使用/输出
$ diff -y --suppress-common-lines file1.txt file2.txt
2:tar-1.23-13.el6.x86_64/ | 2:tar-1.23-15.el6_8.x86_64/
> samba-common-3.6.23-43.el6_9.x86_64/
> samba-winbind-clients-3.6.23-43.el6_9.x86_64/
> samba-winbind-3.6.23-43.el6_9.x86_64/
关于linux - 比较两个文件并以表格形式显示差异 Linux shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44854999/