Skip to main content
added 215 characters in body
Source Link
RavinderSingh13
  • 134.6k
  • 14
  • 61
  • 100

Could you please try following awk and let me know if this helps you. It will look always look for last digits after -:

awk -F' |-' '{sum+=$(NF-1)} END{print sum}'  Input_file

EDIT:

awk -F' |-' '
{
  ++a[$(NF-1)];
  b[$(NF-1)]=b[$(NF-1)]?b[$(NF-1)]+$(NF-1):$(NF-1)
}
END{
  for(i in a){
    if(a[i]>1){
     print i,b[i]}
}}
'   Input_file

Output will be as follows:

4826 9652
0028 56

Could you please try following awk and let me know if this helps you. It will look always look for last digits after -:

awk -F' |-' '{sum+=$(NF-1)} END{print sum}'  Input_file

Could you please try following awk and let me know if this helps you. It will look always look for last digits after -:

awk -F' |-' '{sum+=$(NF-1)} END{print sum}'  Input_file

EDIT:

awk -F' |-' '
{
  ++a[$(NF-1)];
  b[$(NF-1)]=b[$(NF-1)]?b[$(NF-1)]+$(NF-1):$(NF-1)
}
END{
  for(i in a){
    if(a[i]>1){
     print i,b[i]}
}}
'   Input_file

Output will be as follows:

4826 9652
0028 56
Source Link
RavinderSingh13
  • 134.6k
  • 14
  • 61
  • 100

Could you please try following awk and let me know if this helps you. It will look always look for last digits after -:

awk -F' |-' '{sum+=$(NF-1)} END{print sum}'  Input_file