I have a file that has say 50 columns. I want to sum columns 10 to 50, since columns 1-9 have text data. I want to include every column in the output and the final column is the sum.
I can do this using a very long statement:
awk '{X=$0}{split(X,x)}{print X , x[10]+x[11]+x[12]+x[13]+x[14]+x[15]+x[16]+x[17]+x[18]+x[19]+x[20]+x[21]+x[22]+x[23]+x[24]+x[25]+x[26]+x[27]+x[28]+x[29]+x[30]+x[31]+x[32]+x[33]+x[34]+x[35]+x[36]+x[37]+x[38]+x[39]+x[40]+x[41]+x[42]+x[43]+x[44]+x[45]+x[46]+x[47]+x[48]+x[49]+x[50]}' input > output
I was wondering how I could go about cleaning this up? This works fine, but is very slow on my large files.
(also, I have another awk oneliner I'm running after this to drop all columns where the sum is < 1000 using awk '($51 > 999 )'
, can I combine this into the above?)
question from:
https://stackoverflow.com/questions/66051826/awk-sum-row-columns-x-to-y-and-print-as-new-column 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…