gpt4 book ai didi

linux - 如何在 bash shell 脚本中从文件中添加两行数字?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:40:57 26 4
gpt4 key购买 nike

我试图在 shell 中添加文件中的数字,但有点卡住了。我是 bash 的新手,我不知道该怎么做。我的文件示例是这样的。

猫温度

23 49

35 50

我想做的是添加 23 和 35 以及添加 49 和 50。任何想法都会有所帮助。

谢谢。

最佳答案

使用awk:

 awk '{f1+=$1;f2+=$2} END{print f1" "f2}' temp

what if i want to save f1 and f2 to another file call temp1, how can i do that?

将标准输出重定向到文件 temp1

 awk '{f1+=$1;f2+=$2} END{print f1" "f2}' temp > temp1

关于linux - 如何在 bash shell 脚本中从文件中添加两行数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10630840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com