我有一个如下所示的文本文件:
abcd nasj uasdy 3452 2314134
abcd efgh sdfdsf 234553 9323454
abcd asdf asdfasdf 34545 5234523
abcd sdfa sadfad 435232434 3452435
现在我尝试使用 awk
计算第 5 列和第 4 列之间的比率,我试过这个:
BEGIN { printf "%10s %10s" "Column1:", "Ratio:%s" }
{ printf "%10s %10f" $1, ($6)/($5) }
但我一直收到错误提示:
awk: awkRatio.awk:1: fatal: not enough arguments to satisfy format string
`%10s %10sColumn1:'
^ ran out for this one
最佳答案
看起来你在 printf "..."
部分后面漏了一个逗号
尝试:
BEGIN { printf "%10s %10s", "Column1:", "Ratio:" }
{ printf "%10s %10f", $1, ($5)/($4) }
关于Linux:使用 AWK 计算两个值之间的比率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21816906/