How to view related lines from 2 files?

classic Classic list List threaded Threaded
2 messages Options
R W
Reply | Threaded
Open this post in threaded view
|

How to view related lines from 2 files?

R W

Have been using vim for some time (fabulous program)
but have come accross a problem that has me stumped.
Perhaps someone can help me out..

I have 2 text files containing multi-line records that
possibly contain duplicated records.  

I have a script that identifies possible duplicates eg

$./find_duplicates.pl file1 file2
file1:101 possible duplicate at file2:697
file1:123 possible duplicate at file2:703

What I would like to do is step through the duplicates
one by one while viewing the (possibly) matching
record in the other file.

The first half is easy using vim's quickfix mode with
the right errorformat.

But I cant quite figure how to do the second bit: jump
to the related record in the other window. I tried to
use tags but unfortunately tags seems to be limited to
using a single word as the tag wheras I need to match
on a whole line..

Any clues?
 

Send instant messages to your online friends http://au.messenger.yahoo.com 
Reply | Threaded
Open this post in threaded view
|

Re: How to view related lines from 2 files?

A.J.Mechelynck
----- Original Message -----
From: "R W" <[hidden email]>
To: <[hidden email]>
Sent: Monday, August 15, 2005 6:17 AM
Subject: How to view related lines from 2 files?


>
> Have been using vim for some time (fabulous program)
> but have come accross a problem that has me stumped.
> Perhaps someone can help me out..
>
> I have 2 text files containing multi-line records that
> possibly contain duplicated records.
>
> I have a script that identifies possible duplicates eg
>
> $./find_duplicates.pl file1 file2
> file1:101 possible duplicate at file2:697
> file1:123 possible duplicate at file2:703
>
> What I would like to do is step through the duplicates
> one by one while viewing the (possibly) matching
> record in the other file.
>
> The first half is easy using vim's quickfix mode with
> the right errorformat.
>
> But I cant quite figure how to do the second bit: jump
> to the related record in the other window. I tried to
> use tags but unfortunately tags seems to be limited to
> using a single word as the tag wheras I need to match
> on a whole line..
>
> Any clues?

[advertisement snipped]

Have you tried using diff mode? Either when starting Vim

    gvim -d file1 file2

or with an already running Vim

    :e file1
    :diffthis
    :vsplit file2
    :diffthis

Matching lines in both files will then be aligned (and folded), provided of
course that their sequence is the same.

An external "diff" program is needed in your PATH for this to work; Unix
usually has one, for Windows without cygwin I use the one from the GnuWin32
project at sourceforge.

HTH,
Tony.