shell脚本 - “nawk”

时间:2012-01-02 10:43:48

标签: awk sh nawk

您一直在尝试从final_customer_total.txt中读取记录,其中包含已处理文件大小等详细信息。我使用“nawk”命令读取final_customer_total.txt来计算处理的总大小,然后将总和存储到另一个文件中。

变量t =未处理文件的大小
例如,让

吨= 1000

输入文件:

file1 100
file2 250
file3 300

预期产出:

需要处理的总大小:1650

实际输出:

file1 100
file2 250
file3 300
需要处理的总大小:1650

我关注的inupt文件内容也出现在我不想要的输出中! 下面是我试过的命令

cat final_customer_total.txt |nawk '{total = total + $1} END{printf ("\nTotal size :"(total + t)/1024/1024/1024" GB")}'t=$t >>customer_total_size.txt

当我尝试“awk”时,它会受到影响 错误:awk在第1行附近拯救

1 个答案:

答案 0 :(得分:1)

我怀疑你想成为什么:

nawk -v t=$t '
{
    total = total + $1
}
END {
    printf ("Total size needs to be processed: %d GiB\n",(total+t)/1024/1024/1024)
}' final_customer_total.txt > _cts.txt
mv final_customer_total.txt final_customer_total.txt.old
mv _cts.txt final_customer_total.txt