Hi
I have a file with 3 columns. say,
infile:
1 50 68
34 3 23
23 4 56
-------
-------
I want to generate n files from this file using a loop so that 1st column in output file is (column1 of infile/(2*n+2.561))
I am doing like this:
for ((i=1; i<=3; i++))
do
a=`echo "2*$i+2.561" | bc -l`
awk '{ printf"%.8f %.8f %.8f\n", ($1/a), $2, $3 }' infile >> out$i
done
but it seems variable a has to be defined within awk. how can I use i in it? Please help
clx
2
like this?
awk '{r=$1/(2*NR)+2.561; print r,$2,$3}' infile
output:
3.061 50 68
11.061 3 23
6.39433 4 56
To declare a variable within awk use -v option..so the above awk could be as
awk -v var="$a" '{ printf"%.8f %.8f %.8f\n", $1/var, $2, $3 }' infile >> out$i