Operating System - HP-UX
1848559 Members
6973 Online
104033 Solutions
New Discussion

Re: i need a command for sum

 
mariano_4
Occasional Contributor

i need a command for sum

who know some command for sum a list in a file txt?
6 REPLIES 6
Sajid_1
Honored Contributor

Re: i need a command for sum

what abt 'expr' command:
# man expr
learn unix ..
mariano_4
Occasional Contributor

Re: i need a command for sum

thanks for anwnsner.. but

in the file there are the nex

salida.txt

34k
24k
76k
89m
50k
78kb

and i need sum all the numbers.

Rodney Hills
Honored Contributor

Re: i need a command for sum

Usually I use awk-

awk '{s=s+$1}END{print s}' yourfile

This will sum the first field in "yourfile" and print the result.

Hope this helps.

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: i need a command for sum

For a very simplistic script, you can substitue "000" for "k" and "000000" for "m" to scale the numbers-

awk '{sub("k","000");sub("m","000000");s=s+$1}END{printf "%15d\n",s}' yourfile

Hope this helps more...

-- Rod Hills
There be dragons...
mariano_4
Occasional Contributor

Re: i need a command for sum

tanks "Sajid"
it's correct
it's all ok...

see you
harry d brown jr
Honored Contributor

Re: i need a command for sum



How's this??

echo 0 `cat textfile | sed -e "s/ //g" -e "s/RSS/0/" -e "s/M/000K/" -e "s/K/000/" -e "s/^/+ /"` | bc


live free or die
harry
Live Free or Die