PDA

View Full Version : [ubuntu] create a variable and print it into a file



Peter.Paul
November 28th, 2010, 09:09 PM
Hello,

I am trying to calculate an average value and write it into a file. The calculation of the average works perfect, but it seems like, I cannot put it on a variable and print it out.

So, this works perfect

awk 'BEGIN{total=0;} {total+=$1} END{printf (total/50)}' $1tail.txt >> temp.txtAnd this one does not:

variable = awk 'BEGIN{total=0;} {total+=$1} END{printf (total/50)}' $1tail.txt >> temp.txt
echo "$variable is the average. The highest value is $high"
Can you help me out with this?

zipteye
November 29th, 2010, 06:24 AM
Maybe this.




variable = awk 'BEGIN{total=0;} {total+=$1} END{printf (total/50)}'

variable $1tail.txt >> temp.txt

echo "$variable is the average. The highest value is $high"

Peter.Paul
November 30th, 2010, 04:35 PM
this script gives me the error message "variable not found".

zipteye
December 1st, 2010, 05:43 AM
variable = ` awk "BEGIN{total=0;} {total+=$1} END{printf (total/50)}" `

Try that.