cmpcol -d '|' -us X:3 Y:3 > xy-keys.union
####
1st_key_value <1
2nd_key_value <12
3rd_key_value <2
...
####
#!/usr/bin/perl
use strict;
my %key;
open( C, '<', 'xy-keys.union' ) or die "xy-keys.union: $!\n";
while () {
chomp;
my ( $k, $v ) = ( /^ (.*) < \+? ([12]+) \+? $/x ); # ignore dup.key (+) marks
$key{$k} = $v;
}
my %common;
open( I, '<', 'X' ) or die "X: $!\n";
open( O, '>', 'X.out' ) or die "X.out: $!\n";
while () {
my $k = ( split /\|/ )[2];
if ( $key{$k} eq '1' ) {
s/$/|I/;
}
else {
$common{$k} = $_;
}
print O;
}
open( I, '<', 'Y' ) or die "Y: $!\n";
open( O, '>', 'O.out' ) or die "O.out: $!\n";
while () {
my $k = (split /\|/)[2];
if ( $key{$k} eq '2' ) {
s/$/|D/;
}
elsif ( $_ ne $common{$k} ) {
s/$/|U/;
}
print O;
}