thunderkid
Technical User
I am trying to sums up col2 data in following data file
# ----- data.txt -------
alpha 2
alpha 3
beta 4
beta 6
beta 10
gamma 1
alpha 4
alpha 10
desired results
Col1 sums
alpha 9
beta 10
gamma 1
alpha 14
Note that col1 fields may be repeated, but I want to make new calculation when they are repeated.
I have the tried to modify awk code (vgersh99) for another thread below with no success. This awk code sums all col 2 quantities, which is not what I want.
{ a[$1] +=$2 }
END {
for (i in a)
print i, a;
}
thunderkid
# ----- data.txt -------
alpha 2
alpha 3
beta 4
beta 6
beta 10
gamma 1
alpha 4
alpha 10
desired results
Col1 sums
alpha 9
beta 10
gamma 1
alpha 14
Note that col1 fields may be repeated, but I want to make new calculation when they are repeated.
I have the tried to modify awk code (vgersh99) for another thread below with no success. This awk code sums all col 2 quantities, which is not what I want.
{ a[$1] +=$2 }
END {
for (i in a)
print i, a;
}
thunderkid