This is the mail archive of the
mailing list for the Cygwin project.
Re: Cygwin's vanilla sed : capabilities and limitations
- From: "Peter S Tillier" <peter dot tillier at btinternet dot com>
- To: <fergus at bonhard dot uklinux dot net>
- Cc: <cygwin at cygwin dot com>
- Date: Thu, 24 Jul 2003 02:32:56 +0100
- Subject: Re: Cygwin's vanilla sed : capabilities and limitations
- References: <Pine.GSO.email@example.com>
- Reply-to: "Peter S Tillier" <peter dot tillier at btinternet dot com>
Igor Pechtchanski wrote:
> On Wed, 16 Jul 2003, Igor Pechtchanski wrote:
>> On Wed, 16 Jul 2003 firstname.lastname@example.org wrote:
>> > Q2. Is there a way using the supplied sed without major
>> > enhancements to change "abc x def" to "def x abc": that is, to
>> > grab two distinct portions and swap them (using $1,$2 or \1,\2 or
>> > whatever).
>> Sure. 's/^\(.*\) x \(.*\)$/'.
> Oops! Make that 's/^\(.*\) x \(.*\)$/\2 x \1/'.
Or, more efficiently, 's/^\([^ ]*\) x \(.*\)$/\2 x \1/'. Using .* too
early in an RE causes the RE engine to do a lot of (sloooow)
If you say what you mean here then "everything _up to_ the first space
exchanged with everything after the second space" gives my suggestion
Also from Fergus' original mail:
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?
Likewise here: "everything up to the first b" is /^[^b]*b/, so you need
echo aaabbbccc | sed 's/^[^b]*b//' => bbccc
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