加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 添加到包含模式的行的结尾 – 使用sed或awk

发布时间:2020-12-15 16:32:47 所属栏目:安全 来源:网络整理
导读:这里是示例文件 somestuff...all: thing otherthingsome other stuff 我想做的是添加到以all开头的行:像这样: somestuff...all: thing otherthing anotherthingsome other stuff 我可能可以做这使用sed,但我不是真的好sed,所以任何人可以帮助吗? 这对我
这里是示例文件
somestuff...
all: thing otherthing
some other stuff

我想做的是添加到以all开头的行:像这样:

somestuff...
all: thing otherthing anotherthing
some other stuff

我可能可以做这使用sed,但我不是真的好sed,所以任何人可以帮助吗?

这对我有用
sed '/^all:/ s/$/ anotherthing/' file

第一部分是找到的模式,第二部分是一个普通的sed的替换,使用$作为一行的结尾。

如果要在此过程中更改文件,请使用-i选项

sed -i '/^all:/ s/$/ anotherthing/' file

或者您可以将其重定向到另一个文件

sed '/^all:/ s/$/ anotherthing/' file > output

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读