Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 替换UNIX SED中的文本_Regex_Unix_Sed - Fatal编程技术网

Regex 替换UNIX SED中的文本

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

我有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>

参数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>