On Fri, 25 Aug 2006 16:58:38 -0400, Kamaraju Kusumanchi
<[EMAIL PROTECTED]> wrote:

> On Friday 25 August 2006 14:04, Mike wrote:
> > On Fri, 25 Aug 2006, William O'Higgins Witteman might have said:
> > > 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?
> >
> > $ man comm
> 
> Sorry for the nitpicking. But this sometimes might not work. For example
> 
> $cat temp1.txt
> temp3
> temp1
> 
> $cat temp2.txt
> temp2
> temp3
> temp4
> temp1
> temp5
> 
> $comm -3 temp1.txt temp2.txt
>         temp2
> temp1
>         temp4
>         temp1
>         temp5
> 
> $diff temp1.txt temp2.txt | grep '^>'  | cut -f 1 -d ' ' --complement
> temp2
> temp4
> temp5
> 
> The OP did not mention that his files were sorted. So comm command might not 
> be applicable for his case.

Alternatively, Perl offers a solution for files where the lines may be
in any order:

$ cat longfile
one
two
three
four
five
six
seven
eight
nine
ten

$ cat shortfile
nine
six
three

$ perl -e 'open S, $ARGV[0] or die $ARGV[0];
%lines = map { $_ => 1 } <S>;
close S;
open L, $ARGV[1] or die $ARGV[1];
while (<L>) { print unless exists $lines{$_} }
close L;' shortfile longfile
one
two
four
five
seven
eight
ten

-- 
Matthew Winn

Reply via email to