The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 08-28-2007
baghera baghera is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 23
Ok I did as you said:

Code:
data=`cat $2 | xargs -n $1`

#echo $data

columns=$1
i=1
echo $columns

while [ "$columns" -gt 0 ]
do
	awk_cmd=`awk -v i=$1 '{sum+=$i} END {print sum/NR}'`
   	echo "$data | $awk_cmd"
	i=`expr $i + 1`
	columns=`expr $columns - 1`
done
But then I get this kind of error:

>> sh reader4 4 testfil.txt
awk: syntax error near line 1
awk: bailing out near line 1
2 2 1 1
1 1 1 1 |
awk: syntax error near line 1
awk: bailing out near line 1
2 2 1 1
1 1 1 1 |
awk: syntax error near line 1
awk: bailing out near line 1
2 2 1 1
1 1 1 1 |
awk: syntax error near line 1
awk: bailing out near line 1
2 2 1 1
1 1 1 1 |

What I want is that is goes through each column on each run in the while loop and prints the corresponding average. But I really appreciate the help, I have been to some forums where you get slammered because, maybe, stupid questions.