The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 -->
  #4 (permalink)  
Old 08-28-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,418
You don't need the awk_cmd command :
Code:
data=`cat $2 | xargs -n $1`

#echo $data

columns=$1
i=1
echo $columns

while [ "$columns" -gt 0 ]
do
   	echo "$data" | awk -v i=$1 '{sum+=$i} END {print sum/NR}'
	i=`expr $i + 1`
	columns=`expr $columns - 1`
done
If you want to keep it, you must use the eval command :
Code:
	awk_cmd="awk -v i=$1 '{sum+=$i} END {print sum/NR}'"
	echo "$data" | eval $awk_cmd
Jean-Pierre.