gpt4 book ai didi

bash - 使用 awk 在文件上追加列

转载 作者:行者123 更新时间:2023-11-29 09:19:22 27 4
gpt4 key购买 nike

我有来自标准输出的数据列(在我的例子中是对 mysql 的调用),我想在每个循环中附加一个文件中的列。我该怎么办?

Standard output:

a1
a2
....
an

保存在名为 table.dat 的文件中:

table.dat:

a1
a2
....
an

然后产生另一个输出:

Further standard output:

b1
b2
....
bn

附加到 table.dat:

table.dat:

a1 b1
a2 b2
.... ....
an bn

……等等。我可以使用粘贴,但我需要三个步骤:

 line producing standard output > tmpfile;
paste prevfile tmpfile > table
mv table prevfile;

有没有更快的方法,也许是使用 awk?

这个解决方案: Add a new column to the file生成一个空表。

最佳答案

您可以通过读取标准输入来使用这样的粘贴:

paste <(command1) <(command2)

例如

paste <(cat f1) <(cat f2)

代替:

paste f1 f2

关于bash - 使用 awk 在文件上追加列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19796863/

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