I do some replacements in an XML file (I know this is bad but it’s only for quickly testing out some stuff – normally I would use a parser for this) using sed. I have 4 statements which look quite the same, i.e. the matching part differs only in the key
sed -i "s/\(key=\"liferay.db.host\" value=\)\".*\"/\1\"$hostname\"/" "$installer_directory/silent.xml"
sed -i "s/\(key=\"idm.backend.db.host\" value=\)\".*\"/\1\"$hostname\"/" "$installer_directory/silent.xml"
sed -i "s/\(key=\"idm-frontend.portal-tarent.tarent-frontend-host\" value=\)\".*\"/\1\"$hostname\"/" "$installer_directory/silent.xml"
sed -i "s/\(key=\"openid-idp.hostname\" value=\)\".*\"/\1\"$hostname\"/" "$installer_directory/silent.xml"
Now I wonder if there is some way to put these into one sed statement?
Something like
/\(key="(first_key|second_key|third_key)"\) value=\)\".*\"/
This might work for you (GNU sed):
Used alternation to shorten the four commands to one and replaced periods, which may have be interpreted as metacharacters, to match real periods.