use*_*606 9 regex unix shell sed
我想用sed做以下几点
情况1:
*here is some random text constant=randomValue some more random text*
Run Code Online (Sandbox Code Playgroud)
我想在constant =之后直接替换randomvalue,同时保持线的其余部分保持原样,结果如下:
*here is some random text constant=substituteValue some more random text*
Run Code Online (Sandbox Code Playgroud)
案例2:
*here is some random text constant= randomValue some more random text*
Run Code Online (Sandbox Code Playgroud)
类似于第一个但是在constant = string之后有一个空格,所以输出就是
*here is some random text constant= substituteValue some more random text*
Run Code Online (Sandbox Code Playgroud)
对于我一直在尝试使用的案例:
echo $line | sed 's/server=.*\ /sever=\<SrvrName\>/'
Run Code Online (Sandbox Code Playgroud)
你可以使用这个sed:
sed 's/\( constant = *\)[^ ]*/\1substituteValue/' <<< "$line"
Run Code Online (Sandbox Code Playgroud)