How to put multiple files’ output side by side for comparision in Linux ?

Sometimes we need to compare different files side by side on our computer screen.

Lets say you have 5 files and want to check them side by side.

To achieve this, we will look at an interesting command today known as paste.

The command is by default available with the default Redhat, NGELinux or Centos Install.

1. Viewing Multiple files together

### Lets create three files first
[root@nglinux test]# echo "hello" > abc
[root@nglinux test]# echo "hello 2" > abc2
[root@nglinux test]# echo "hello 3" > abc3

### Now lets paste all these three files side by side.
[root@nglinux test]# paste abc*
hello	hello 2	hello 3
[root@nglinux test]# 

2. Viewing 6 files together in columns

Now lets increase the number of files to view from 3 to 6 files.

### Create three new files
[root@nglinux test]# echo "Welcome 1" > abc4
[root@nglinux test]# echo "Welcome 2" > abc5
[root@nglinux test]# echo "Welcome 3" > abc6
[root@nglinux test]# 

### Paste all six files as columns
[root@nglinux test]# paste abc*
hello	hello 2	hello 3	Welcome 1	Welcome 2	Welcome 3
[root@nglinux test]# 

3. Comparing two files in Linux

### Two files can be compared using sdiff
[root@nglinux test]# sdiff abc abc2
hello							      |	hello 2

### However it will show an error if we try to display more than 2 files.
[root@nglinux test]# sdiff abc abc2 abc3
sdiff: extra operand `abc3'
sdiff: Try `sdiff --help' for more information.

Leave a Reply

Your email address will not be published.