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 From: "Hannu E K Nevalainen" To: "ML CygWIN" Subject: RE: OT: Using sed - guru help wanted. Date: Tue, 21 Oct 2003 00:54:27 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 In-Reply-To: <3F9448F1.91AFE2F3@dessent.net> > From: Brian Dessent > Sent: Monday, October 20, 2003 10:43 PM > Hannu E K Nevalainen wrote: > > > $ echo ' a b / c d e ' | \ sed -e 's/ *\(.*\) *\/ *\(.*\) */.\1.\2./' > > > > .a b .c d e . > > > > I want the output to be '.a b.c d e.' - that is; strip out the > > trailing spaces. > > > > HOW do I achieve that? ( \s = any ws, \S = any non ws ) > > > > Obviously \(.*\) grabs/includes the last space. My brain has stoppped > > working, so right now I can't work around that :-I > > Personally, I can't stand the "basic" style regexps that sed uses, and > I prefer perl-compatible. You can use the non-greedy modifier, for > example: > > command | perl -pe 's!^ +(.*) +/ +(.*?) +$!.\1.\2.!' Thanks a lot! Now all I have to do is understand where the difference is ;-7 $ echo ' a b / c d e ' | \ sed -re 's!^ +(.*) +/ +(.*?) +$!.\1.\2.!' .a b.c d e. It seems as the -r flag to sed made _this_ expression work right OOTB. Hmm... lets see; $ echo ' a b / c d e ' | sed -e 's/^ \+\(.*\) \+\/ \+\(.*\) \+$/.\1.\2./' .a b.c d e. So THERE was the problem, some escaping needed. As it seems my query wasn't that well formed... i.e. remove any leading and/or trailing spaces on the parts. Parts separated by the slash. This seems to do exactly what I'm after; $ echo 'a b/c d e ' | \ sed -re 's- *(.*[^ ]) */ *(.*[^ ]) *$-.\1.\2.-' Thanks for the input, Brian and Igor. /Hannu E K Nevalainen, B.Sc. EE - 59?16.37'N, 17?12.60'E -- printf("Timezone: %s\n", (DST)?"UTC+02":"UTC+01"); -- --END OF MESSAGE-- -- 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/