Taking sum up all values inside the file

Hi,

Taking sum up all values inside the file by using the below command:

paste -sd+ filenmae | bc

Getting some error like "0705-001: building space exceeded on line1 stdin"

The original data looks like

SPACE SPACE SPACE 0.123 [.\] JOBNAME1
SPACE SPACE 20.325 [.\] JOBNAME2
SPACE SPACE SPACE SPACE SPACE 402.238 [.\] JOBNAME3

Like that, some thousands of records for four files. By using sed command, removing all the starting spaces in a file and storing vlaues(i.e., cpu time) column alone in a file and trying take to the count by using paste command.

I tried to use different scenarios to take the count by using awk, eventhough am getting same error.

The error is displaying for few files only. I verified the file contents there is no spaces or empty rows.

Thanks for you help in advance.

Expecting this .. ??

$ nawk '{$1=$1}; {sum+=$1}END{print sum}' infile
422.809

I found out the problem...

paste -sd+ filename | bc 

The ablove code is working only for 350 records, to take sum up values inside a file. Performance wise, it will execute very fast. If it is more than 350 records it won't work.

We should use the below code and again the drawback is it will take more time to take sum. Performance wise its dead slow.

while read value
   do
      total_cpu=$(echo "$value + $total_cpu" | bc)
   done<filename

So, i was using both codes like

if recourd count <= 350
   use paste command
else
    use looping