sed to replace partial string
13,765
You can use this sed:
sed 's/\( constant = *\)[^ ]*/\1substituteValue/' <<< "$line"
Author by
Admin
Updated on July 20, 2022Comments
-
Admin almost 2 years
I would like to do the following by using sed
case 1:
*here is some random text constant=randomValue some more random text*
I would like to replace randomvalue directly after constant= while keeping the rest of the line intact so the result would look like:
*here is some random text constant=substituteValue some more random text*
case2:
*here is some random text constant= randomValue some more random text*
similar to the first one but with a space after the constant= string, so the output would be
*here is some random text constant= substituteValue some more random text*
For case one i've been trying to use:
echo $line | sed 's/server=.*\ /sever=\<SrvrName\>/'