Code:
gawk 'BEGIN{FS=",";FILEO="outfile";MODULO=100;FILET="outtmp"}
{
if (substr($1,3,1)=="-"){
array[$5","$1","$5","$6","substr($1,1,2)","$2","$7","$4]++;
}
else{
arraytmp[$5","$1","$5","$6","$1","$2","$7","$4]++;
}
if (NR%MODULO==0){
while((getline line <FILEO)>0){
split(line,a,",");
b=a[1]","a[2]","a[3]","a[4]","a[5]","a[6]","a[7]","a[8];
if(array[b]){
line=b","array[b]+a[9];
array[b]=0;
}
else{
if(arraytmp[b]){
line=b","arraytmp[b]+a[9];
arraytmp[b]=0;
}
}
print line >FILET;
}
for (counter in array){
if(array[counter]>0){
print counter","array[counter] >FILET;
}
}
for (counter in arraytmp){
if(arraytmp[counter]>0){
print counter","arraytmp[counter] >FILET;
}
}
delete array;
delete arraytmp;
close(FILET);
close(FILEO);
system("mv "FILET" "FILEO);
}
}
END{
while((getline line <FILEO)>0){
split(line,a,",");
b=a[1]","a[2]","a[3]","a[4]","a[5]","a[6]","a[7]","a[8];
if(array[b]){
line=b","array[b]+a[9];
array[b]=0;
}
else{
if(arraytmp[b]){
line=b","arraytmp[b]+a[9];
arraytmp[b]=0;
}
}
print line >FILET;
}
for (counter in array){
if(array[counter]>0){
print counter","array[counter] >FILET;
}
}
for (counter in arraytmp){
if(arraytmp[counter]>0){
print counter","arraytmp[counter] >FILET;
}
}
delete array;
delete arraytmp;
close(FILET);
close(FILEO);
system("mv "FILET" "FILEO);
}
' infile