[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Compare two 'available' files?



On Wed, Sep 08, 1999 at 01:21:31AM +0200, Thomas Schoepf wrote:
> Yeah, I know. But it's not exactly what I want. I have a few slink
> machines around, each with a quite unique configuration. So I want a
> listing of packages that are new in 2.1r3 (not only new with respect to a
> specific machine)... and I'm also curious about which packages changed
> between releases.
> 
> I guess it's time to practise Perl a little bit again...

A good way to tell when you don't feel like doing real work...

Here is a small script which compares two available files run
something like this:

% avail.pl available1 available2
Package Mosaic only in second
Package afbackup-client-i only in first
Package afbackup-i only in first
Package dpkg changed version: 1.4.0.35 to 1.4.0.34
Package dpkg-dev changed version: 1.4.0.35 to 1.4.0.34
...

No guarantees, warranties or copyrights


#!/usr/bin/perl -w
#
# Compare two available files
# avail.pl file1 file2

use strict;
my($package, $version, %pkgs, %vers, %vers2);
$/ = "\n\n";
my($file1) = shift;
my($file2) = shift;

open(AVAIL, $file1) or die "Can't first open available";

while (<AVAIL>) {
  ($package, $version) = get_info($_);
  $pkgs{$package} = 1;
  $vers{$package} = $version;
}

close AVAIL;
open(AVAIL, $file2) or die "Can't open second available";

while (<AVAIL>) {
  ($package, $version) = get_info($_);
  $pkgs{$package} = (exists $pkgs{$package}) ? 3 : 2;
  $vers2{$package} = $version;
}

# print out results
foreach (sort keys %pkgs) {
  
  print "Package $_ only in first\n"
    if $pkgs{$_} == 1;

  print "Package $_ only in second\n"
    if $pkgs{$_} == 2;

  if ($pkgs{$_} == 3 &&
      ($vers{$_} ne $vers2{$_})) {
    print "Package $_ changed version: $vers{$_} to $vers2{$_}\n";
  }
}

sub get_info {
  my($rec) = @_;
  my($package, $version);
  
  $package = $1 if $rec =~ /Package:\s+(.*)\n/;
  $version = $1 if $rec =~ /Version:\s+(.*)\n/;
  
  ($package) or die "Didn't get package name:\n$rec";
  ($version) or die "Didn't get version number:\n$rec";
  
  return ($package, $version);
}
  
  



-- 
Jim Mintha                                       Email: jim@ic.uva.nl
System Administrator                              Work: +31 20 525-4919
Informatiseringscentrum                      	  Home: +31 20 662-3892
University of Amsterdam               Debian GNU/Linux: jmintha@debian.org
_There are always Possibilities_                 http://jim.ultralinux.org


Reply to: