View two text files at the same time side by side

Solution 1:

Use Vim, with scrollbind set. For example:

vim -O +'windo set scrollbind' /etc/profile /etc/profile.pacnew

enter image description here

With scrollbind, if you scroll in one window, the other bound windows also scroll at the same time. To have line numbers, a ~/.vimrc containing a minimum of the following two lines is enough:

set nocompatible
set number

Not that you need a vimrc for this - it can be done entirely from the commandline:

vim -NO +'set nu' +'windo set scrollbind' file1 file2 ...

Solution 2:

How about a command from early days of Unix?

pr -m file1 file2

For example:

pr  -m English Spanish

2016-01-18 00:34                                                  Page 1

this is something                esto es algo
hello, there                     Hola

Update: You can fit the output to the size of your terminal by using less

pr -m file1 file2 | less

Solution 3:

From the GUI you could try meld:

screenshot

It's not exactly what you're asking for, but it should be as much as useful for your purpose.

Additional sections of text will be highlighted in green, different sections of text will be highlighted in blue (and likewise in different sections of text additional characters will be highlighted in a darker blue).

Works also for more than two files at the time.

Solution 4:

On the command line you can use

 paste file1 file2 | less -N