1753479 Members
4959 Online
108794 Solutions
New Discussion юеВ

awk help

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

awk help

Hi all,

I am using awk to get a string of numbers from a file:

cat file |awk '{print $2}'

this gives me several numbers:

25324
136753
234
1231214

how can I now use awk to add these figures together so I can get a total?

Thanks
hello
3 REPLIES 3
Peter Godron
Honored Contributor
Solution

Re: awk help

lawrenzo,
one-line solution:
cat file | awk 'BEGIN{N=0};{N+=$2};END{print N}'
RAC_1
Honored Contributor

Re: awk help

awk '{(s+=$2)} END {printf "%d\n",s}' your_file
There is no substitute to HARDWORK
lawrenzo_1
Super Advisor

Re: awk help

great cheers guys
hello