#!/usr/bin/perl

use strict;
use warnings;

my ($passwd1, $passwd2, $field) = @ARGV;

sub parse_passwd {
    my ($file) = @_;
    my %attr;
    if (open(my $fh, '<', $file)) {
        while (my $line = <$fh>) {
            chomp($line);
            my @fields = split(':', $line);
            $attr{$fields[0]} = $fields[$field];
        }
        close($fh);
    } else {
        die "Can't open $file";
    }
    return %attr;
}

my %attr1 = parse_passwd($passwd1);
my %attr2 = parse_passwd($passwd2);

foreach my $user (sort keys %attr1) {

    if (!exists($attr2{$user})) {
        next;
    }
    my $val1 = $attr1{$user} || '';
    my $val2 = $attr2{$user} || '';

    if ($val1 ne $val2) {
        print "$user: `$val1' ne `$val2'\n";
    }
}
