Skip to main content
deleted 1 character in body
Source Link

You can use two indexed arrays to store the count of requests and the existing nodes for each name, and before printing, you can compare the array of existing nodes with your fixed array of nodes, for example:

awk 'BEGIN {
       totalNodes=" 36totalNodes="36 54 69 76"
     }
     NR==1 {print "<Name> <Nodes> <Count of Requests>"};
     NR>1 {
         count[$1]+=$4; nodesTmp[$1]=nodesTmp[$1]" "$3;
         }
     END{
         for (i in count) {
             if(totalNodes!=nodesTmp[i]) {
                 split(totalNodes,tmp);
                 for(j in tmp){
                     if(nodesTmp[i]!~tmp[j]){
                         nodes[i]=nodes[i]" NA"
                     }
                     else {
                         nodes[i]=nodes[i]" "tmp[j]
                     }
                 }
             }
             else{
                 nodes[i]=nodesTmp[i]
             }; 
             print i, nodes[i], count[i] | "sort"
         };
     }' temp.log

You can use two indexed arrays to store the count of requests and the existing nodes for each name, and before printing, you can compare the array of existing nodes with your fixed array of nodes, for example:

awk 'BEGIN {
       totalNodes=" 36 54 69 76"
     }
     NR==1 {print "<Name> <Nodes> <Count of Requests>"};
     NR>1 {
         count[$1]+=$4; nodesTmp[$1]=nodesTmp[$1]" "$3;
         }
     END{
         for (i in count) {
             if(totalNodes!=nodesTmp[i]) {
                 split(totalNodes,tmp);
                 for(j in tmp){
                     if(nodesTmp[i]!~tmp[j]){
                         nodes[i]=nodes[i]" NA"
                     }
                     else {
                         nodes[i]=nodes[i]" "tmp[j]
                     }
                 }
             }
             else{
                 nodes[i]=nodesTmp[i]
             }; 
             print i, nodes[i], count[i] | "sort"
         };
     }' temp.log

You can use two indexed arrays to store the count of requests and the existing nodes for each name, and before printing, you can compare the array of existing nodes with your fixed array of nodes, for example:

awk 'BEGIN {
       totalNodes="36 54 69 76"
     }
     NR==1 {print "<Name> <Nodes> <Count of Requests>"};
     NR>1 {
         count[$1]+=$4; nodesTmp[$1]=nodesTmp[$1]" "$3;
         }
     END{
         for (i in count) {
             if(totalNodes!=nodesTmp[i]) {
                 split(totalNodes,tmp);
                 for(j in tmp){
                     if(nodesTmp[i]!~tmp[j]){
                         nodes[i]=nodes[i]" NA"
                     }
                     else {
                         nodes[i]=nodes[i]" "tmp[j]
                     }
                 }
             }
             else{
                 nodes[i]=nodesTmp[i]
             }; 
             print i, nodes[i], count[i] | "sort"
         };
     }' temp.log
Source Link

You can use two indexed arrays to store the count of requests and the existing nodes for each name, and before printing, you can compare the array of existing nodes with your fixed array of nodes, for example:

awk 'BEGIN {
       totalNodes=" 36 54 69 76"
     }
     NR==1 {print "<Name> <Nodes> <Count of Requests>"};
     NR>1 {
         count[$1]+=$4; nodesTmp[$1]=nodesTmp[$1]" "$3;
         }
     END{
         for (i in count) {
             if(totalNodes!=nodesTmp[i]) {
                 split(totalNodes,tmp);
                 for(j in tmp){
                     if(nodesTmp[i]!~tmp[j]){
                         nodes[i]=nodes[i]" NA"
                     }
                     else {
                         nodes[i]=nodes[i]" "tmp[j]
                     }
                 }
             }
             else{
                 nodes[i]=nodesTmp[i]
             }; 
             print i, nodes[i], count[i] | "sort"
         };
     }' temp.log