My problme is two fold. First is printing a regex match. The second is the actual regex.
Problem 1: I'm trying to print the output of yum grouplist --verbose into a format that I can put into a puppet conf file. Therefore, I need to print more than just the match so sed and grep -o won't work (at least not that I know of).
Here are examples of some of the output:
Maori Support (maori-support) [mi]
Mongolian Support (mongolian-support) [mn]
Mynamar (Burmese) Support (burmese-support) [my]
Nepali Support (nepali-support) [ne]
I want all output lines that contain (*-support) to be printed out as:
'maori-support': ensure => absent;
'mongolian-support': ensure => absent;
'burmese-support': ensure => absent;
'nepali-support': ensure => absent;
I've already completed doing it manually, but I'd like to figure out how to do it as a one-line just for knowledge sake.
I've tried awk and perl to no avail. The closest I've been able to get is using perl like this:
$ yum grouplist --verbose | perl -nwe 'print "$1: ensure\t=> absent;\n" if /\((.+-support)\)'
Problem 2: however, that doesn't include the single quotes into the output. There's also the problem that one of the output lines looks like this:
Mynamar (Burmese) Support (burmese-support) [my]
The above regex matches everything from the first opening parenthesis. I don't know how to get it to start the match from the second parenthesis. I've tried modifying the regex to be non-greedy with ? but it just continues ot match (Burmese) Support (burmese-support)