I have the regex
I was able to get this to work with GNU sed with
sed -n 's/\(\/foo\/bar\/\(GW\|GREV\)[^\/]*\).*/\1/p'
But that was a modern GNU sed and I'm on Solaris 10 with an ancient sed. Maybe it is possible to port it but that's beyond my ability. I do have perl 5.8 available to me, though, so my question: how can I get the matching subgroup printed in a perl one liner?
 The gist of it is I want to match all directories that match the form /foo/bar/GWxxx, /foo/bar/GREVxxx and print that root directory. So for the following strings, I always get
/foo/bar/GREV123as the captured group:
/foo/bar/GREV123 /foo/bar/GREV123/ /foo/bar/GREV123/etc