Add numbers in third code with conditions on the 1st and 2nd


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Add numbers in third code with conditions on the 1st and 2nd
# 8  
Old 01-13-2014
Quote:
Originally Posted by TheTransporter
Hello ctsgnb,

It does not give any output...
Code fixed, check my previous post ...
# 9  
Old 01-13-2014
awk '{ if ( $1 > $2 ) { arr[$2$1] += $3 } else { arr[$1$2] += $3 } }END{ for (i in arr) { print i, arr[i] } }' file
# 10  
Old 01-13-2014
Quote:
Originally Posted by matrixmadhan
awk '{ if ( $1 > $2 ) { arr[$2$1] += $3 } else { arr[$1$2] += $3 } }END{ for (i in arr) { print i, arr[i] } }' file
$1 and $2 will be concatenated in the output when you print i which may not be a "userfriendly" output
# 11  
Old 01-14-2014
Quote:
Originally Posted by ctsgnb
$1 and $2 will be concatenated in the output when you print i which may not be a "userfriendly" output
ctsgnb@ That's right. I guess its sufficient to give pointers or versions, its upto the OP to tweak it and get it done. Its not requirement, product delivery contract Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Want the UNIX code - I want to sum of the 1st column wherever the first 2nd and 3rd columns r equal

I have the code for the below things.. File1 has the content as below 8859 0 subscriberCreate 18 0 subscriberPaymentMethodChange 1650 0 subscriberProfileUpdate 7668 0 subscriberStatusChange 13 4020100 subscriberProfileUpdate 1 4020129 subscriberStatusChange 2 4020307 subscriberCreate 8831... (5 Replies)
Discussion started by: Mahen
5 Replies
Login or Register to Ask a Question