On Wed, Mar 24, 2010 at 11:13 PM, Philip Guenther <guent...@gmail.com> wrote: > 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. >> B B sed -n -e 's/.*\(PATTERN\).*/\1/p' > > The 'portable' solution that doesn't have those problems is to use a > nuke^W^Wperl: > B B perl -nle 'while(m((PATTERN))g){print $1}'
ahem, is perl really everything these days? and how portable that is? is awk completely disregarded as a usable tool? awk '{ s = $0; while (match(s,"PATTERN")) { print substr(s, RSTART, RLENGTH); s = substr(s, RSTART + RLENGTH); } }' this gives me the same results are your perl string (which is shorter of course, after all it's perl). it also gives the same results are grep -o on a debian system i have access to. also awk uses, AFAIK, ERE, in which case the greediness may be controlled.