Possible to view two text files side by side (read only)

diff()text;

In emacs, we can view two text files side by side.

Is it also possible to do so in some simpler/lighter applications such as less?

Only viewing, no editing.

Best Answer

The less command by itself cannot do any diff'ing. You can use the diff -y command to show the diff of 2 files side-by-side and then pipe that into less however.

Method #1 - using diff + less

This will create 2 sample files.

$ seq 100 > 1.txt
$ seq 10 100 > 2.txt

Now diff the 2 files:

$ diff -y 1.txt 2.txt | less
1                                                             <
2                                                             <
3                                                             <
4                                                             <
5                                                             <
6                                                             <
7                                                             <
8                                                             <
9                                                             <
10                                                              10
11                                                              11
12                                                              12
13                                                              13
...

Method #2 - using vimdiff

You can also use vimdiff in readonly mode, -R.

$ vimdiff -R 1.txt 2.txt 

   ss #1