I need to multiply a column in a file with float numbers, say with (1.0 + 0.25)
I have a extracted column 3 ( with Numbers) with awk command from file file1.txt
awk '{ print $3 }' file1.txt > coloumn1
1.0
1.2
1.3
I want to multiply all column values with (1.0 + 0.25)to achieve the following values. requirement is to use different p1 values. p1 is 1.1
( 1.0*(p1+0.25))
( 1.2*(p1+0.25))
( 1.3*(p1+0.25))
1.250
1.500
1.625
My script is
#bin/bash
p1=1.0
val=`echo $p1 + 0.25 | bc`
awk -F, '{$1*=$val}1' OFS=, coloumn1 > coloumn_mod
But above awk command is not returning the expected result ,
Could you please help correcting the above command ?
awk
doesn't return the expected result is that because in the single quotes' ... '
in which you have enclosed the program (as is recommended), shell variables are not expanded. If you are interested to learn more about this (and the peculiarities of it), see here on how to import shell variables intoawk
. – AdminBee Nov 19 '20 at 09:37