开发者

Shell Scripting and use of gawk along with arithmetic operations

开发者 https://www.devze.com 2023-03-03 17:11 出处:网络
I have a tab delimited file and I want to perform some mathematical calculations on the columns present in file.

I have a tab delimited file and I want to perform some mathematical calculations on the columns present in file.

let the file name be sndf and $tag have some integer value, I want to first find difference between the values of column 3 and 2 then divide column 4 value with the value in $tag again divide the resultant with the difference in values of column 3 and 2 and final result is multiplied by 100.

cat $sndf | gawk '{for (i = 1; i <= NF; i += 1) {
    printf "%f\t"  $3 -$2 "\t",  (((($4/"'$tag'")/($3-$2)))*100);
} printf "\n"}'>normal_开发者_Python百科wrt_region

the command is writing answer 4 times instead of one time to the output file..... can u all suggest an improvement? thank you

SOLUTION: Dear all, I have solved the problem, thank you all for reading the problem and investing your time.


the command is writing answer 4 times instead of one time to the output file, can u all suggest an improvement?

Don't use the for loop if you don't need one?

cat $sndf | gawk '{ printf "%f\t"  $3 -$2 "\t", (((($4/"'$tag'")/($3-$2)))*100) }'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号