在UNIX SED中替换文本

时间:2012-04-10 08:20:05

标签: regex unix sed

我有包含

的text1.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>

我想用 abc

取代这部分这可以是任何值 - 没有硬编码

什么应该是正确的SED命令? 请注意,由于环境限制,我无法灵活地使用任何语言,如perl,python或ruby~,并且只能使用Unix命令。 并且没有硬编码,除了 param1

提前多多感谢!

2 个答案:

答案 0 :(得分:1)

您想要的调用是

sed -e 's/param1=.*/param1=abc/' text1.txt

答案 1 :(得分:1)

听起来你想要像s/<.\+>$/<abc>/

这样的东西
$ 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>