2009/1/15 igor denisov <denisovigor1...@rambler.ru>:
> Hello there.
>
> There is a problem here.
>
> input:
>  34523
>  9485
>  394
>  3456
>
> awk '{subtruct-=$1} END {print subtruct}' input
>
> output:
> -47858
> same thing but without minus with
>
> awk '{sum+=$1} END {print sum}' input
>
> output:
> 47858
>
> Why in both cases the code sums the field?

Are you expecting '0' since the input file contains a space in front
of the number?  In that case, run awk with "-F '[ ]'", e.g.

awk -F '[ ]' '{sum+=$1} END {print sum}' input

Cheers,
Andreas

-- 
Andreas Kahari
Somewhere in the general Cambridge area, UK

Reply via email to