Bash Sum up for spezific Numbers

Hello everyone,

I need your assistance with bash.
I want to sum up some numbers, that's not the big problem i think, but the values i want to some depending on another number.

For example, I have a file with some rows of content.
Number 1, Number 2, other content.

I want to sum up number 2 for every row number 1 is the same.
So i can get one row which shows me the number 1 first and then the sum of number 2, so i can see the sum for each number 1.

Hope you understand what i mean. :confused:
Is that possible with bash?

Sincerely
Bruder_Bruno

Sample data please? And welcome.

Hey, thanks for the welcome.

I attached 2 files.
example 1.txt is how it looks like in my file.
example 2.txt is what i want as output.

Hope this helps.

Any/no attempts from your side?

Your sample files aren't too easy, and I guess they're not representative. Anyhow, try

awk '
NR==1 || !NF    {next}
NR==2           {print "Number1 Number2"
                 next
                }
                {sum[$4]+=$3}
END             {for (s in sum) print s, sum}
' /tmp/example\ 1.txt 
Number1 Number2
99334523 35
97637083 57
99310914 13
92317170 54
95706975 24
1 Like

Thanks, that works.

I tried to do the splitting with cut but i then didn't know how to sum the segment depending on Number 1.

But this works great. Thanks