Skip to main content
added 227 characters in body
Source Link
user232326
user232326

Without solving the several special character issues:
Awk is able to process the whole file a lot faster:

#!/bin/bash
LINE_COUNT=0
FILE_SLOWEST=1
FILE_LONGEST=1

awk '{ val=$NF+0;
       if(NR==1)  {min=val;max=val}
       if(max<val){max=val}
       if(min>val){min=val}
       sum+=val
     } END {
          avg=sum/NR
          print (sum,avg,max,min)
     }' logfile.txt  | {

        read SUM AVG MAX MIN
 
        echo "The Sum of values           is = $SUM"
        echo "The averaged value of times is = $AVG"
        echo "The maximum of times        is = $MAX"
        echo "The minimum of times        is = $MIN"
    
    }

Understand that to keep the read values after the pipe has ended you need something like:

read SUM AVG MAX MIN < <(awk ...)

Without solving the several special character issues:
Awk is able to process the whole file a lot faster:

#!/bin/bash
LINE_COUNT=0
FILE_SLOWEST=1
FILE_LONGEST=1

awk '{ val=$NF+0;
       if(max<val){max=val}
       if(min>val){min=val}
       sum+=val
     } END {
          avg=sum/NR
          print sum,avg,max,min
     }' logfile.txt  | read SUM AVG MAX MIN
 
echo "The Sum of values           is = $SUM"
echo "The averaged value of times is = $AVG"
echo "The maximum of times        is = $MAX"
echo "The minimum of times        is = $MIN"

Without solving the several special character issues:
Awk is able to process the whole file a lot faster:

#!/bin/bash
LINE_COUNT=0
FILE_SLOWEST=1
FILE_LONGEST=1

awk '{ val=$NF+0;
       if(NR==1)  {min=val;max=val}
       if(max<val){max=val}
       if(min>val){min=val}
       sum+=val
     } END {
          avg=sum/NR
          print(sum,avg,max,min)
     }' logfile.txt  | {

        read SUM AVG MAX MIN
        echo "The Sum of values           is = $SUM"
        echo "The averaged value of times is = $AVG"
        echo "The maximum of times        is = $MAX"
        echo "The minimum of times        is = $MIN"
    
    }

Understand that to keep the read values after the pipe has ended you need something like:

read SUM AVG MAX MIN < <(awk ...)
Calculate sum, avg, min, max
Source Link
user232326
user232326

Without solving the several special character issues:
Awk is able to process the whole file a lot faster:

#!/bin/bash
LINE_COUNT=0
FILE_SLOWEST=1
FILE_LONGEST=1

FILE_SUM=$awk '{ val=$NF+0;
       if(max<val){max=val}
    awk '  if(min>val){sum+=$NFmin=val}
       sum+=val
     } END {
          avg=sum/NR
          print sum,avg,max,min
     }' logfile.txt  | read )SUM AVG MAX MIN

echo "The Sum of values           is = $SUM"
echo "The averaged value of times is = $AVG"
echo "The maximum of times        is = $MAX"
echo "The minimum of times        is = $MIN"

Without solving the several special character issues:
Awk is able to process the whole file a lot faster:

#!/bin/bash
LINE_COUNT=0
FILE_SLOWEST=1
FILE_LONGEST=1

FILE_SUM=$(    awk '{sum+=$NF}END{print sum}' logfile.txt    )

Without solving the several special character issues:
Awk is able to process the whole file a lot faster:

#!/bin/bash
LINE_COUNT=0
FILE_SLOWEST=1
FILE_LONGEST=1

awk '{ val=$NF+0;
       if(max<val){max=val}
       if(min>val){min=val}
       sum+=val
     } END {
          avg=sum/NR
          print sum,avg,max,min
     }' logfile.txt  | read SUM AVG MAX MIN

echo "The Sum of values           is = $SUM"
echo "The averaged value of times is = $AVG"
echo "The maximum of times        is = $MAX"
echo "The minimum of times        is = $MIN"

Source Link
user232326
user232326

Without solving the several special character issues:
Awk is able to process the whole file a lot faster:

#!/bin/bash
LINE_COUNT=0
FILE_SLOWEST=1
FILE_LONGEST=1

FILE_SUM=$(    awk '{sum+=$NF}END{print sum}' logfile.txt    )