Hereaposs the scenario. You have a big string and you want to replace part of it with another string.
For example you want to change quotI am writing a line todayquot to quotI am writing a line nowquot.
In this quick tutorial Iaposll show you how to replace a substring natively in Bash. Iaposll also show the sed command example as an extension.
Bash has some built-in methods for string manipulation. If you want to replace part of a string with another this is how you do it.
Create a string variable consisting of the line x201CI am writing a line todayx201D without the quotes and then replace today with now.
Did you understand what just happened In the syntax quotlinetodaynowquot line is the name of the variable where Iaposve just stored the entire sentence. Here Iaposm instructing it to replace the first occurrence of the word today with now. So instead of displaying the contents of the original variable it showed you the line with the changed word.
News Link: https://linuxhandbook.com/replace-string-bash/.