I have two files, one very long and the other much shorter.
Every line in the short file is also in the long file.  What I
need is a file with every line in the long file *not* in the
short file.  Is there an easy way to have vim provide me with
my desired complementary file?

If you happen to know that your short-file only contains words
(no funky meta-characters that would cause trouble for a search),
you can do something like the following:

in your short file, execute

:[EMAIL PROTECTED]@:g/&/d

This will transform your short file into a bunch of Ex commands.
 You can then yank them all

        :%y

switch over to your buffer containing your long file, and then
execute it like a macro:

        @"

If there's a possiblity that items in the short-file aren't in
the long file, you might have to change that first item to
something like:

:[EMAIL PROTECTED]@:sil! g/&/d

which would hopefully supress any errors regarding the pattern
not being found in the file.

You might also want to work on copies of your original files (or
refrain from writing the output, as you've bunged with them) so
you don't lose your originals.

If you have to allow characters that would trip up a regular
expression (periods, asterisks, etc), you could make a prelim
pass in your short file to clean them up with something like this
incomplete command:

        :%s/.*/\=escape(submatch(0), './*[\\^$~')

You might have to tweak that set of characters at the end so that
the right family of characters gets escaped.

Just a few ideas.

-tim



Reply via email to