This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
Re: OT: Using sed - guru help wanted.
- From: Brian Dessent <brian at dessent dot net>
- To: ML CygWIN <cygwin at cygwin dot com>
- Date: Mon, 20 Oct 2003 13:43:29 -0700
- Subject: Re: OT: Using sed - guru help wanted.
- Organization: My own little world...
- References: <NGBBLLIAMFLGJEOAJCCEKEILDFAA.garbage_collector@telia.com>
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/