4

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.

  • Using tmux or screen makes this quite straightforward. – jasonwryan Jul 9 '14 at 2:29
  • Do you need them to scroll in tandem? Why not just open two terminals with separate less commands? Does this need to be a command line program? When asking for tools, you need to be as specific as possible so we don't waste your and our time suggesting things that won't work for you. – terdon Jul 9 '14 at 3:16
  • @jasonwryan: that is a great solution. thanks – Tim Jul 9 '14 at 14:43
11

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

  • how can I jump between different files? – Thushi Jul 9 '14 at 9:09
  • @Thushi - how do you mean? Within vimdiff? – slm Jul 9 '14 at 9:56
  • Yeah,Within vimdiff. If I have opened two files,lets say a.txt and b.txt then I want to switch between those two files. – Thushi Jul 9 '14 at 10:58
  • 2
    Ctrl+w will switch b/w windows. – slm Jul 9 '14 at 12:06
3

I am not sure if it is possible using less command. However, it is possible using the below command. From here,

pr -m -t one.txt two.txt

One more option that is useful though doesn't display side by side is,

tail -f file1 -f file2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.