Monday, January 5, 2015

Problem: sum for each column in a text file(ignoring the first line)

Solution:
cat file |awk -F " " 'function abs(x){return ((x < 0.0) ? -x : x)}NR>1{sum1+=$1; sum2+=abs($2)} END{print sum1;print sum2}'

Example:
$cat file
1000    1000
8       8
2       -2
3       0
7       5
$.my.sh
20
15

No comments: