1

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

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

t=1000

输入文件 :

文件 1 100 文件
2 250文件
3 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 行附近跳伞

4

1 回答 1

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
于 2012-01-21T16:50:17.263 回答