1

我有 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没有硬编码

提前非常感谢!

4

2 回答 2

1

你想要的调用是

sed -e 's/param1=.*/param1=abc/' text1.txt
于 2012-04-10T08:28:50.253 回答
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>
于 2012-04-10T09:07:12.620 回答