nawk question - addition of a column
Hi,
I have a file, like the following, where I would like to addition up column 5 (length). DISK DEVICE TAG OFFSET LENGTH FLAGS ARG01-05_CU0212 c3t110d2s2 c3t110d2 25186048 2076928 - ARG03-15_CU0561 c3t110d0s2 c3t110d0 16777216 4171520 - ARG03-15_CU0562 c3t110d1s2 c3t110d1 4194304 16754432 - cat out | nawk -F" " '/[0-9]+/ { sum += $5 ; print $sum}' Above is the nawk that I am trying. Firstly check it's a number, and then addition up column 5. I read a few random web-pages, and I thought this would work, but does'nt... I am using nawk on Solaris although I think that nawk exists on many Linux distributions too. Many thanks for any tips. |
Code:
nawk ' /-$/ {sum+=$5} END{ printf("%12.0f\n", sum)} ' file |
All times are GMT -5. The time now is 08:50 AM. |