我想使用sed
执行以下操作案例1:
*here is some random text constant=randomValue some more random text*
我想在constant =之后直接替换randomvalue,同时保持线的其余部分完好无损,结果如下:
*here is some random text constant=substituteValue some more random text*
情况2:
*here is some random text constant= randomValue some more random text*
类似于第一个但是在constant = string之后有一个空格,所以输出将是
*here is some random text constant= substituteValue some more random text*
对于我一直试图使用的案例:
echo $line | sed 's/server=.*\ /sever=\<SrvrName\>/'
答案 0 :(得分:7)
您可以使用此sed:
sed 's/\( constant = *\)[^ ]*/\1substituteValue/' <<< "$line"