I have a string in a variable from which I need to extract a substring. The substring can occur anywhere in the string, but it will only occur once.
template_line_1="allocate channel c11 device type disk maxopenfiles 1 connect 'sys/<connect_pwd>@TKTP21' format '/u902/backup/TKTP2/database/backup_%d_<static_date_seq>_%t%s%p';"
template_line_2="allocate channel c11 device type disk maxopenfiles 1 format '/u902/backup/TKTP2/database/backup_%d_<static_date_seq>_%t%s%p' connect 'sys/<connect_pwd>@TKTP21';"
Considering each of the two variables above, what I need to to is extract the string beginning with word " connect " (surrounded by a space) and ending with the second single quote (') after the " connect ".
The resulting extraction from both example variables would be:
I received a helpful direction from a person here that directed me to use following form of sed:
echo $template_line_1 | sed "s/.*\(connect .*'\)/\1/"
which works fine as long as the connect appears at the end of the string, but that is not always the case.
Please consider the two example variables above and the resulting extracted string as the problem to solve. It does not have to be sed, but it appears that it could work with sed with some modification.