Issue
lets say I have a string variable variable
var="This line is with OldText"
I want to find and replace the text inside this variable The method that I tried is,
echo $var | sed -i "s/OldText/NewText/g" >> result.log
in this case this gives an error saying "no input files". The expected output is ,
"This line is with NewText"
what is the correct method to do this using sed, awk or any other method.
Solution
You don't use -i
, as that's for changing a file in place. If you want to replace the value in the variable, you need to reassign to it.
Answered By - ndc85430 Answer Checked By - Marie Seifert (WPSolving Admin)