gpt4 book ai didi

linux - 如何将 StdOut 添加到文件的顶部(而不是底部)?

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

我在 linux 中使用 bash 来完成将内容添加到文件顶部的操作。到目前为止,我知道我可以通过使用临时文件来完成这项工作。所以我是这样做的:

tac lines.bar > lines.foo
echo "a" >> lines.foo
tac lines.foo > lines.bar

但是有没有更好的方法来做到这一点而不必编写第二个文件?

最佳答案

echo a | cat - file1 > file2

和 shellter 的一样

和 sed 在一行中。

sed -i -e '1 i<whatever>' file1

这将插入到 file1 中。 the sed example i referred to

关于linux - 如何将 StdOut 添加到文件的顶部(而不是底部)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9372431/

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