我有一个看起来像这样的文本文件:

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 "..." -part之后错过了一个逗号
尝试:

BEGIN { printf "%10s %10s", "Column1:", "Ratio:" }
    { printf "%10s %10f",  $1, ($5)/($4) }

关于linux - Linux : Useing AWK to Calculate Ratio Between 2 Values,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21816906/

10-11 08:26