How to replace a line in a file if a line starts from another line with sed?
For example, replace this line:
connection = sqlite://keystone:[YOURPASSWORD]@[YOURIP]/keystone
Using this line:
connection = mysql://keystone: password@10.1.1.10 /keystone
Answer:
sed '/^start_string/s/search_string/replace_string/'
Information at http://www.gnu.org/software/sed/manual/sed.html#Addresses
You can do it simply:
sed -ri 's/sqlite/mysql/g' YOURFILE
sed '/^string1/ { s,string2,string3, }' file
This will replace string2 with string3 on all lines starting with line1.
If you want to change the entire line that starts with the template and ends with enything else, you can use the c description command Example
c
sed -i '/^connection = sqlite/c\connection = mysql://keystone: password@10.1.1.10 /keystone' your_file