我想通过使用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 =字符串后有一个空格,因此输出为
*here is some random text constant= substituteValue some more random text*
对于一种情况,我一直在尝试使用:
echo $line | sed 's/server=.*\ /sever=\<SrvrName\>/'
您可以使用此sed:
sed 's/\( constant = *\)[^ ]*/\1substituteValue/' <<< "$line"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句