gpt4 book ai didi

unix - 如何使用 sed 追加到现有行

转载 作者:行者123 更新时间:2023-12-02 05:27:40 27 4
gpt4 key购买 nike

我想在不创建新行的情况下输出附加字符串的文件内容。

到目前为止,我的命令将附加的字符串放在一个新行上:

sed -e 'a foo' file.txt
>> file contents...
>> foo

我希望输出看起来像这样:

>> file contents...foo

最佳答案

使用 sed(在 ArchlinuxMinix 上测试成功):

sed '$s/$/foo/' file.txt

$ 开头,表示文件的结尾。

如果你需要在每一行添加 foo :

sed 's/$/foo/' file.txt

在最新的上下文中,$ 表示行的结尾

关于unix - 如何使用 sed 追加到现有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12850556/

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