Code:
#!/bin/bash
#sar.sh
i=1
while read myline
do
if [ $i -eq 1 ]
then
echo "Report Date: $(cut -d" " -f4 ornek2-c.txt)" > output.txt
elif [ $i -gt 3 ]
then
echo $myline > temp.txt
proc=$(cut -d" " -f3 temp.txt)
echo $proc > temp.txt
cat temp.txt >> temp2.txt
fi
i=$(expr $i + 1)
done <ornek2-c.txt
index=$(expr $i - 4)
cat temp2.txt | awk '{ sum+=$1 } END {print sum}'
average=$(echo "scale=4; $sum/$index"|bc)
echo $average
exit 0
the output after execution(./sar.sh):
144
42.91
(standard_in) 1: parse error
i created ornek2-c.txt file with "sar -c -f ornek2.sa > ornek2-c.txt" command.i'm trying to find the average value of the proc/s column in ornek2-c.txt.
Thanks in advance.
Comment