Another sort/Awk solution
(if your files are not already sorted as the samples you posted):
Code:
sort -t\| -k1,2 file1 file2|awk '{
x[$1,$2]++
y[NR] = $0
} END {
for (i = 1; i <= NR; i++)
print y[i] > ((x[substr(y[i],1,5)] > 1) ? "file3" : "file4")
}' SUBSEP="|" FS="|"
Use nawk or /usr/xpg4/bin/awk on Solaris.
P.S. For variable column width: you should not use substr, but split for example:
Code:
sort -t\| -k1,2 file1 file2|awk '{
x[$1,$2]++
y[NR] = $0
} END {
for (i = 1; i <= NR; i++)
{
tmp = y[i]
split(tmp,z)
print tmp > ((x[z[1],z[2]] > 1) ? "file3" : "file4")
}
}' SUBSEP="|" FS="|"