首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用SED将字符串插入到找到子字符串的字符串中

如何使用SED将字符串插入到找到子字符串的字符串中
EN

Stack Overflow用户
提问于 2016-06-16 00:42:27
回答 1查看 39关注 0票数 0
代码语言:javascript
运行
复制
$ cat f1
My name is Bruce and my surname is

我想使用SED查找“Bruce”,然后将“Lee”附加到找到“Bruce”的行尾

然后是一个更棘手的…。我想插入….a string…在一条线上我找到了一些东西。举个例子

代码语言:javascript
运行
复制
$ cat f2
My name is Yacov and I am from Israel.
I used to be a programmer but then I found love for a woman who told me to become a teacher.

我想使用SED在我找到字符串“programmer”的地方插入字符串“excellent”。我想在子字符串“programmer”的开头插入这个字符串

EN

回答 1

Stack Overflow用户

发布于 2016-08-06 22:04:01

你已经试过了吗?

代码语言:javascript
运行
复制
$ cat f1
My name is Bruce and my surname is
$ sed 's/^.*Bruce.*$/& Lee/' f1
My name is Bruce and my surname is Lee
$ cat f2
My name is Yacov and I am from Israel.
I used to be a programmer but then I found love for a woman who told me
to become a teacher.
$ sed 's/programmer/excellent programmer/' f2
My name is Yacov and I am from Israel.
I used to be a excellent programmer but then I found love for a woman 
who told me to become a teacher.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37841194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档