Search code examples
linuxbashshellunixredhat

Compare two files and display difference in table form linux shell script


I'm trying to compare the difference of two files which are a list of packages before and after an update and displaying it in a form that is easily readable.

Basically some of my contents would be like this:

Pre-update:

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/

Post Update:

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/

Expected Output:

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/

Basically show the updates under both files and the additions only under the new file.

I don't mind other ways of displaying it as long as it nicely formatted so like oldpackagename --> newpackagename or something along that route.


Solution

  • If you would like nice side-by-side output, you can use:

    $ diff -y --suppress-common-lines file1.txt file2.txt
    

    Example Use/Output

    $ 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/