Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <000801c35183$af605ec0$5c16989e@oemcomputer> Reply-To: "Peter S Tillier" From: "Peter S Tillier" To: Cc: References: Subject: Re: Cygwin's vanilla sed : capabilities and limitations Date: Thu, 24 Jul 2003 02:32:56 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Igor Pechtchanski wrote: > On Wed, 16 Jul 2003, Igor Pechtchanski wrote: > >> On Wed, 16 Jul 2003 fergus AT bonhard DOT uklinux DOT net 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/'. > Igor Or, more efficiently, 's/^\([^ ]*\) x \(.*\)$/\2 x \1/'. Using .* too early in an RE causes the RE engine to do a lot of (sloooow) backtracking. If you say what you mean here then "everything _up to_ the first space exchanged with everything after the second space" gives my suggestion above. 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 Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/