Calculate total sum from a file

The file content is dynamic and using this format:

name1 number1
name2 number2
name3 number3
name4 number4
....................

Need a smooth way to calculate the sum of all the numbers in that file (number1 + number2 + number3 + number4........ = total )

Oh thats an easy one. There is also 'bc' but that would be for really hard core math, and then there is "let".. but dont worry with those.. you can just use awk.

-bash-3.2$ cat test.txt
one 1
two 2
three 3
four 4
five 5
six 6
seven 7
eight 8
nine 9
ten 10

-bash-3.2$ awk '{count += $2;} END { print count; }' test.txt
55

Works like a harm, thanks!

No problem!

Hi all,
I am new to this forums so was not able to find to post new forums hence i posted in the already existing form please help me with the below requirement

I have a requirement as below I want to grep xyz and get the result domain name as "unix.com"

3.209.12.09 xyz xyz.unix.com

Something like this:

$
$ cat input.txt
3.209.12.09 xyz xyz.unix.com
$
$ awk '{sub("xyz.","",$3); print $3}' input.txt
unix.com
$

tyler_durden

Thanks for your help !!! But need some more of your help

There is an another clause over here which i found just now ... xyz.unix.com can come any where in the line it need not be at $3 every time

sed  -n 's/.*\(xyz\.[aA-zZ][aA-zZ]*\.com\).*/\1/p ' filename

-Devaraj Takhellambam

$
$ cat input.txt
3.209.12.09 xyz xyz.unix.com
3.209.12.09 xyz.unix.com xyz
xyz.unix.com xyz 3.209.12.09
$
$ perl -ne 's/^.*xyz\.([^ ]*).*/$1/; print' input.txt
unix.com
unix.com
unix.com
$

tyler_durden

$ cat input.txt
3.209.12.09 xyz xyz.unix.com

xyz.unix.com can come any where in the command line ... it be like

3.209.12.09 xyz.unix.com xyz so in this case i guess we cant we use $3 in that case how to go about it ..

Did you try the sed command I posted?

sed  -n 's/.*\(xyz\.[aA-zZ][aA-zZ]*\.com\).*/\1/p ' filename

-Devaraj Takhellambam

It worked now Thanks a look . Can you tell me how to post a new form .. I read the manuals but was bit ambiquity in there