添加到包含模式的行的末尾 - 用awk或者sed [英] Add to the end of a line containing a pattern - with sed or awk

查看:166
本文介绍了添加到包含模式的行的末尾 - 用awk或者sed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是示例文件

somestuff...
all: thing otherthing
some other stuff

我想要做的是增加与启动所有行:是这样的:

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

我也许可以做到这一点使用SED,但我不是在SED确实不错,所以任何人都可以用它帮助?

I probably can do this using sed, but I am not really good in sed, so could anyone help with it?

推荐答案

这对我的作品

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

的第一部分是一个模式来查找和第二部分是用普通的sed的取代 $ 为一个行的末尾

如果你想在此过程中改变文件,使用 -i 选项

If you want to change the file during the process, use -i option

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

或者你也可以把它重定向到另一个文件

Or you can redirect it to another file

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

这篇关于添加到包含模式的行的末尾 - 用awk或者sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆