Operating System - HP-UX
1753305 Members
6292 Online
108792 Solutions
New Discussion юеВ

Re: Sum of some data (easy points ...)

 
SOLVED
Go to solution
Olivier Decorse
Respected Contributor

Sum of some data (easy points ...)

Hi,
i'm searching how to do the sum of data in a file.
For example, file contains :
15 a
15 b
30 c
I want to do :
cat file | awk '{print $1 }' | unix_command_that_do_a_sum
and receive :
60

Thank's in advance.
They say "install windows 2k, xp or better", so i install unix !
4 REPLIES 4
H.Merijn Brand (procura
Honored Contributor

Re: Sum of some data (easy points ...)

# perl -nle'END{print$sum}$sum+=$_' file

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Dietmar Konermann
Honored Contributor
Solution

Re: Sum of some data (easy points ...)

cat file | awk '{sum=sum+$1} END {print sum}'
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Cheryl Griffin
Honored Contributor

Re: Sum of some data (easy points ...)

Olivier Decorse
Respected Contributor

Re: Sum of some data (easy points ...)

Very quick !

Thanks !
Olivier.
They say "install windows 2k, xp or better", so i install unix !