22

I have two text files. Each line represents a line in one language. I need to check if the alignment always fits. Therefore I need a program that displays both text files at the same time with line numbers.

I tried diffuse, but that tries to align the files - if by accident two lines are equal, the whole line-wise visual comparison does not work.

0

5 Answers 5

31

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 ...
1
  • Thanks. I didn't need scrollbind, so it was just -O I was missing. I normally use gt and gT with the -p switch for multiple tabs. Alas those shortcuts don't work in this context; it seem CTRL-W w does the job (vi.stackexchange.com/a/39124).
    – user643722
    Mar 13 at 12:21
13

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
1
  • 4
    If I may suggest so, pipe the output to less -N to show the line numbers together. pr -m file1 file2 | less -N . Jan 17, 2016 at 19:08
11

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.

6
  • I do like & use meld, kdiff3, even sdiff; but if I just want to view two files side by side that are (supposed to be) different (eg, i18n translation resource bundles -- the property matches, value does not; looking for missing properties), then the attempts to line up matching lines & mark lines that are different is actually a negative.
    – michael
    Jan 18, 2016 at 17:19
  • @michael_n I'm at a loss to understand why that would be a negative. Maybe I'm missing the point, but if you use meld you should have noticed that in cases like the case you're describing lines are highlighted in a lighter blue and the specific additional characters in a darker blue, making the exact difference coming out instantly. Or am I missing something?
    – kos
    Jan 18, 2016 at 17:38
  • You are absolutely correct, and I should have clarified; the problem is that these tools don't have a config option to expect and allow that certain differences should be there (afaik). In some cases, they consider the whole file too different to even bother to line up. Eg, a useful option (with my example: msg.text="Hello" vs msg.text="Bonjour") would be to ignore part of the two files by either "first N chars", or regexp: "^.*="
    – michael
    Jan 18, 2016 at 17:44
  • Actually, I think sdiff does have an option to ignore by regexp (but I'm not positive). Still, if it's just free-form text from French & English, there's no need to highlight anything, and any attempt to match up lines -- as I mentioned -- would be a negative. Sometimes, we just wants see files side by side (and that's the essence of the original question, as I understood it).
    – michael
    Jan 18, 2016 at 17:47
  • @michael_n Actually I just noticed the language comparison thing, for some reason initially I thought they needed a more general purpose text comparison tool. Probably you're right, I should delete this, though I'm also considering that questions titled as generically as this one usually attract lots of visits from search engines (e.g. if I Google "file side by side Ubuntu" this is currently the third result). So maybe it's better if it stays in this case. After all it shouldn't hurt. The exact answer(s) make the top of the stack already.
    – kos
    Jan 18, 2016 at 18:08
5

On the command line you can use

 paste file1 file2 | less -N
0

If you're looking at translations you might find Poedit useful. It can display the two texts side by side for you and is made for working with translations.

2
  • 2
    instead of just pasting links to solution, you should explain it 'how' too
    – Alex Jones
    Jan 18, 2016 at 12:48
  • This one seems to be limited to working with gettext.
    – carnendil
    Jan 18, 2016 at 17:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .