Regex 替换UNIX SED中的文本
我有text1.txt,其中包含Regex 替换UNIX SED中的文本,regex,unix,sed,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 - n
<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>
参数1=
我想将此部分替换为这可以是任何值-无硬编码的为abc
正确的SED命令应该是什么?
请注意,由于环境限制,我不能灵活地使用任何语言,如perl、python或ruby~,只能使用Unix命令。
除param1之外,没有硬编码
提前多谢 您想要的调用是
sed -e 's/param1=.*/param1=abc/' text1.txt
听起来你想要的是
s/$/
:
$cat test1.txt
参数1=
$sed's/$/'test1.txt
参数1=
可能会有帮助。注释中的所有示例值如何?@shiplu您能否澄清注释的构成,因为OP的问题text1.txt
是一个普通的文本文件,所以任何东西都可能表示注释?我向OP提问以澄清这可能会更改注释中的所有示例值。否?如果您的意思是六个字符的序列param1=
将始终使用abc
回复其行中的其余字符,即使它出现在“注释”中,则为是。但OP从未提及任何评论。
$ 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>