parsing - awk to parse csv file -


my input file is:

1601260800434:0:0:0:0:0:157:154:1022:1020:764:765:0:0:0:0:0:0:3:0:0:0:796:223:0:596:168:13247:12178:0 1601260800434:0:0:0:0:0:144:143:1100:1103:914:912:0:0:0:0:0:0:0:0:0:0:822:280:0:715:196:13469:12248:0 1601260815434:0:0:0:0:0:184:178:1005:1006:830:829:0:0:0:0:0:0:2:0:0:0:781:225:0:629:200:13227:12170:0 1601260815434:0:0:0:0:0:182:181:1304:1307:912:914:0:0:0:0:0:0:1:0:0:0:988:317:0:720:193:13537:12330:0 1601260830434:0:0:0:0:0:162:157:1064:1065:873:873:0:0:0:0:0:0:5:0:0:0:846:219:0:705:168:13217:12176:0 1601260830434:0:0:0:0:0:173:168:1273:1273:1004:1002:0:0:0:0:0:0:5:0:0:0:939:332:0:771:229:13531:12328:0 

how can have sum per column columns when first field same? 1 total 1601260800434, 1 1601260815434, etc. expect output:

1601260800434:0:0:0:0:0:301:297:2122:2123:1678:1677:0:0:0:0:0:0:3:0:0:0:1618:503:0:1311:364:26716:24426:0 1601260815434:0:0:0:0:0:366:359:2309:2313:1742:1743:0:0:0:0:0:0:3:0:0:0:1769:542:0:1349:393:26764:24500:0 1601260830434:0:0:0:0:0:335:325:2337:2338:1877:1875:0:0:0:0:0:0:10:0:0:0:1785:551:0:1476:397:26748:24504:0 

any idea awk code should be? code should take account number of fields/columns. many thanks!

edit: other solution marked possible duplicate not check when first field changes.

awk rescue!

$ awk -f: '{keys[$1]; for(i=2;i<=nf;i++) sums[$1,i]+=$i}         end{for(k in keys)                {printf "%s",k;                 for(i=2;i<=nf;i++) printf "%s", fs sums[k,i];                 print ""                }            }' file 1601260830434:0:0:0:0:0:335:325:2337:2338:1877:1875:0:0:0:0:0:0:10:0:0:0:1785:551:0:1476:397:26748:24504:0 1601260800434:0:0:0:0:0:301:297:2122:2123:1678:1677:0:0:0:0:0:0:3:0:0:0:1618:503:0:1311:364:26716:24426:0 1601260815434:0:0:0:0:0:366:359:2309:2313:1742:1743:0:0:0:0:0:0:3:0:0:0:1769:542:0:1349:393:26764:24500:0 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -