delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/10/20/16:43:49

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
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: <3F9448F1.91AFE2F3@dessent.net>
Date: Mon, 20 Oct 2003 13:43:29 -0700
From: Brian Dessent <brian AT dessent DOT net>
Organization: My own little world...
X-Accept-Language: en,en-US
MIME-Version: 1.0
To: ML CygWIN <cygwin AT cygwin DOT com>
Subject: Re: OT: Using sed - guru help wanted.
References: <NGBBLLIAMFLGJEOAJCCEKEILDFAA DOT garbage_collector AT telia DOT com>
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - host.linuxsv3.net
X-AntiAbuse: Original Domain - cygwin.com
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - dessent.net
Note-from-DJ: This may be spam

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.!'

Brian

--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019