This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Cygwin's vanilla sed : capabilities and limitations


Brian Dessent wrote:
> fergus@bonhard.uklinux.net wrote:
>
>> Q1. Querying info sed reveals the expression matcher to be "greedy",
>> matching the longest possible string. Is there a way to make it
>> match the shortest possible, so that echo aaabbbccc | sed 's/^.*b//'
>> (altered but similar) grabs aaab not aaabbb?
>
> If you have perl available (or just a tool that uses perl-compatible
> regexps, i.e. grep -P) you can add the '?' character after any
> qualifier to get the non-greedy version, i.e. '*?' is the non-greedy
> '*', '??' is the non-greedy '?', etc.  But this is a feature of pcre,
> which I don't believe applies to sed in any shape or form.  However,
> most sed scripts are pretty easy to do in perl with little
> modification, so if you
> require this function that's what I'd do.
>
> Brian

The GNU sed maintainer Paolo Bonzini also maintains a version of sed
called ssed (super sed) that does support PCREs in addition to BREs and
EREs (which are both now supported in GNU sed 4.x+).

For more on sed:
http://sed.sourceforge.net/

HTH

Peter S Tillier
"Who needs perl when you can write dc, sokoban,
arkanoid and an unlambda interpreter in sed?"


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]