gpt4 book ai didi

linux - 添加新的数字列

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:45:21 24 4
gpt4 key购买 nike

我正在编写以下代码以在 for 循环中使用 awk 从现有文件中提取数据。

for c in {1..300}
do
awk '{if($28==1) print $12,$26,$28}' file1.txt > file2.txt
done

没关系,我有 file2.txt现在,我想添加一个新列,其中包含从上面的 for 循环生成的 c。我这样做了,但它不起作用。

awk '{if($28==1) print $12,$26,$28, paste c}' file1.txt > file2.txt

这仅在我将 c 替换为实数(例如 1,2,...最后,我想将 file1.txt 附加到 file2.txt,即每次循环运行时都会将新数据添加到 file2.txt。我有这个,但它似乎不是最好的:

awk <file2.txt>> file_final.txt

你能给我一些建议吗?谢谢你!芳

使用下面 William 推荐的方法,我能够生成我想要的输出。非常感谢!

最佳答案

rm file2.txt
for c in $(seq 1 300); do
awk '$28==1{print $12,$26,$28,c}' c=$c file1.txt >> file2.txt
done

关于linux - 添加新的数字列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37824516/

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