Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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 ...
share|improve this answer

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
share|improve this answer
3  
If I may suggest so, pipe the output to less -N to show the line numbers together. pr -m file1 file2 | less -N . – Serg Jan 17 at 19:08
    
@Serg thanks, nice suggestion – edward torvalds Jan 18 at 7:54

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.

share|improve this answer
    
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_n Jan 18 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 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_n Jan 18 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_n Jan 18 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 at 18:08

On the command line you can use

 paste file1 file2 | less -N
share|improve this answer

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.

share|improve this answer
1  
instead of just pasting links to solution, you should explain it 'how' too – edward torvalds Jan 18 at 12:48
    
This one seems to be limited to working with gettext. – carnendil Jan 18 at 17:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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