首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >替换UNIX中的文本

替换UNIX中的文本
EN

Stack Overflow用户
提问于 2012-04-10 08:20:05
回答 2查看 1.4K关注 0票数 1

我有text1.txt,它包含

代码语言:javascript
复制
<this can be anything, any number of line - no hardcoded>
<this can be anything, any number of line - no hardcoded>
     param1=<this can be any value - no hardcoded>
<this can be anything, any number of line - no hardcoded>
<this can be anything, any number of line - no hardcoded>

我想用替换这个部分,它可以是任何值-没有硬编码的,用abc

什么是正确的SED命令?请注意,由于环境限制,我没有使用任何语言(如perl、python或ruby ~)的灵活性,只能使用Unix命令。除了param1之外,没有硬编码。

提前谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-10 08:28:50

你想要的调用是

代码语言:javascript
复制
sed -e 's/param1=.*/param1=abc/' text1.txt
票数 1
EN

Stack Overflow用户

发布于 2012-04-10 09:07:12

听起来你想要像s/<.\+>$/<abc>/一样的东西

代码语言:javascript
复制
$ cat test1.txt

<this can be anything, any number of line - no hardcoded>
<this can be anything, any number of line - no hardcoded>
     param1=<this can be any value - no hardcoded>
<this can be anything, any number of line - no hardcoded>
<this can be anything, any number of line - no hardcoded>

$ sed 's/<.\+>$/<abc>/' test1.txt

<abc>
<abc>
     param1=<abc>
<abc>
<abc>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10085360

复制
相关文章

相似问题

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