On Wed, Mar 24, 2010 at 1:06 PM, Philip Guenther <guent...@gmail.com> wrote: ... > Hmm, missing quote, and the expressions can be combined, but as a > portable solution this is indeed the right answer. > sed -n -e 's/.*\(PATTERN\).*/\1/p'
Actually, there are two bug in that, an obvious one and a subtle one. The obvious one is that it only prints one match per line instead of printing all the matches. The subtle one is that if the pattern can match in multiple overlapping positions, it will report the match with the *latest* start instead of the *earliest* start (because the leading ".*" is greedy). The 'portable' solution that doesn't have those problems is to use a nuke^W^Wperl: perl -nle 'while(m((PATTERN))g){print $1}' Philip Guenther