Quantcast
Channel: Active questions tagged bash+awk - Ask Ubuntu
Viewing all articles
Browse latest Browse all 102

awk adding up two rows if the rows have a matching name

$
0
0

I am trying to take a csv file that looks like

customerID,firstname,lastname,charge5efc522,Romo,goodrick,37.894a7f057,jeny,vel,38.395efc522,Romo,goodrick,39.00

and make it into

firstname,lastname,chargetotal,customerIDROMO,goodrick,76.89,5efc522jeny,vel,38.39,4a7f057

so far I know that I can do

awk '{arr[$1]+=$4;}END{FOR (i in arr) {print i, arr[i];}'< file

any help would be appreciated


Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>