#!/bin/sh

PATH=/bin:/usr/bin

if test $# -ne 2
then
    echo usage: uidconflict file1 file2 >&2
    exit 1
fi

(
    if test "x$1" = x-
    then
        cat
    else
        cat "$1"
    fi | sed 's/^/file1:/'

    sed 's/^/file2:/' "$2"

) | awk -F: '
$1 == "file1" {
    # just store data
    uid[$2] = $4
    logname[$4] = $2
}
$1 == "file2" {
    # diagnose
    if (uid[$2] != "" && uid[$2] != $4)
        printf "logname %s has uid %s in file 1 and %s in file 2\n", $2, uid[$2], $4
    if ($4 + 0 >= 20 && logname[$4] != "" && logname[$4] != $2)
        printf "uid %s has logname %s in file 1 and %s in file 2\n", $4, logname[$4], $2
}
'



# (note: in the second 'if' statement we prepend the 'x' to both sides to
#  avoid '-' being taken as an option)
