(standard_in) 1: parse error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hta1984
    New Member
    • Oct 2006
    • 7

    (standard_in) 1: parse error

    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
    ornek2-c.txt: http://www.rafb.net/paste/results/xKMpYT30.html

    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.
  • hta1984
    New Member
    • Oct 2006
    • 7

    #2
    Originally posted by hta1984
    Code:
    cat temp2.txt | awk '{ sum+=$1 } END {print sum}'
    average=$(echo "scale=4; $sum/$index"|bc)
    Code:
    sum=$( cat temp2.txt | awk '{ sum+=$1 } END {print sum}' )
    average=$(echo "scale=4; $sum/$index" | bc)
    editing two lines as above solved the problem.

    Comment

    Working...