简体   繁体   English

Shell脚本和使用gawk以及算术运算

[英]Shell Scripting and use of gawk along with arithmetic operations

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. 让文件名为sndf$tag有一些整数值,我想首先找到第3列和第2列的值之间的差值,然后将第4列值除以$tag的值再次将结果除以列值的差值3和2,最终结果乘以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_wrt_region

the command is writing answer 4 times instead of one time to the output file..... can u all suggest an improvement? 该命令正在写回答4次而不是一次写入输出文件.....你们都可以建议改进吗? 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? 该命令正在写入答案4次而不​​是一次写入输出文件,你们都可以建议改进吗?

Don't use the for loop if you don't need one? 如果您不需要,请不要使用for循环?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM