./fact 00/00/0000 99/99/9999 1 >/dev/null
awk -F"^" ' 
FILENAME==ARGV[1] { pr[$1"^"$2"^"$3"^"$4]=$5"^"$6 }
FILENAME==ARGV[2] { rg[$1"^"$2"^"$3"^"$4]=$5 }
END {
for (i in pr) if (rg[i]!="")
{
print i"^"pr[i]"\n"i"^"rg[i] > "PAGOS/CALCE"
rg[i]=""
pr[i]=""
}
for (i in rg) if (rg[i]!="" && pr[i]!= "")
{
 print i"^"pr[i]"\n"i"^"rg[i]
rg[i]=""
pr[i]=""
}
for (i in pr) if (pr[i]!="") print i"^"pr[i] 
for (i in rg) if (rg[i]!="") print i"^"rg[i]
} ' PAGOS/PR1 PAGOS/REG | sort | 
awk -F"^" ' 
NF == 5 {
r1=NR
fr=substr($3,9)
ir=$1"^"$2
inr=$1"^"$2"^"$3"^"$4
rg[inr]=$5 }
NF == 6 {
fp=substr($3,9)
r2=NR
ip=$1"^"$2
inp=$1"^"$2"^"$3"^"$4
pr[inp]=$5"^"$6 }
ir==ip && absol(r1-r2)==1 && absol(fr-fp) <4 {
#print r1,r2,fr,fp > "PAGOS/CASI"
print inr"^"rg[inr] >"PAGOS/CASI"
print inp"^"pr[inp] >"PAGOS/CASI"
rg[inr]=""
pr[inp]=""
r1=""
r2=""
}
function absol(x) { if (x <0) return (-x)
else return (x)}
END {
for (i in pr) if (pr[i]!="") print i"^"pr[i] 
for (i in rg) if (rg[i]!="") print i"^"rg[i]
} '  -  | sort >PAGOS/NOCAL
awk -F"^" '
FILENAME==ARGV[4] && cta[$5$6]!="" { cta[$5$6]="" ;next } 
FILENAME==ARGV[5] && cta[$5$6]!="" { cta[$5$6]="" ;next } 
cta[$5$6]!="" { print FILENAME; print cta[$5$6]; print $0 ; print "))))))))))))" }
cta[$5$6]=="" { cta[$5$6]=$0  }
END {

for (i in cta) if (cta[i]!="") print cta[i]
}
' PAGOS/CALCE PAGOS/CASI PAGOS/NOCAL PAGOS/PR1 PAGOS/REG >PAGOS/DUP

awk -F"^" '
FILENAME==ARGV[1] { cta[$1$2]=$0  ; next}
FILENAME==ARGV[2] { cta[$1]=$0  ; next}
cta[$5$6]!=""  { print cta[$5$6] }'  PAGOS/ONCOV tmp/F1 PAGOS/CALCE >PAGOS/CALCE.dat

awk -F"^" '
FILENAME==ARGV[1] { cta[$1$2]=$0  ; next}
FILENAME==ARGV[2] { cta[$1]=$0  ; next}
cta[$5$6]!=""  { print cta[$5$6] }'  PAGOS/ONCOV tmp/F1 PAGOS/CASI >PAGOS/CASI.dat
awk -F"^" '
FILENAME==ARGV[1] { cta[$1$2]=$0  ; next}
FILENAME==ARGV[2] { cta[$1]=$0  ; next}
cta[$5$6]!=""  { print cta[$5$6] }'  PAGOS/ONCOV tmp/F1 PAGOS/NOCAL >PAGOS/NOCAL.dat

awk -F"^" '
FILENAME==ARGV[1] { cta[$1$2]=$0  ; next}
FILENAME==ARGV[2] { cta[$1]=$0  ; next}
cta[$5$6]!=""  { print cta[$5$6] }'  PAGOS/ONCOV tmp/F1 PAGOS/DUP >PAGOS/DUP.dat
