替换文本
我有一个包含替换文本
<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>
text1.txt我想更换这部分这可以是任何值 - 没有硬编码与ABC
应该是什么是正确的SED命令? 请注意,由于环境限制,我不能灵活地使用任何语言,如perl,python或ruby〜,只能使用Unix命令。 除了之外没有硬编码参数1
非常感谢!
你想要的调用是
sed -e 's/param1=.*/param1=abc/' text1.txt
这可能会更改评论中的所有示例值。没有? – 2012-04-10 08:33:53
如果你的意思是六个字符的序列'param1 ='将始终使用'abc'填充剩余的字符,即使它出现在“注释”中,那么是的。但OP从未对评论发表任何评论。 – 2012-04-10 08:36:26
非常感谢Ray Toal – iwan 2012-04-12 07:40:00
这听起来像你想要的东西像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>
[这太问题(http://stackoverflow.com/questions/1074450/sed替换部分)可能会有所帮助。 – 2012-04-10 08:25:17
评论中的所有样本值如何? – 2012-04-10 08:34:11
@shiplu你能否澄清一下构成注释的内容,按照OP的问题'text1.txt'是一个普通的文本文件,所以任何东西都可以表示注释? – beny23 2012-04-10 08:37:30