delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/10/22/15:42: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
From: "Hannu E K Nevalainen" <garbage_collector AT telia DOT com>
To: <cygwin AT cygwin DOT com>
Subject: RE: OT: Using sed - guru help wanted.
Date: Wed, 22 Oct 2003 21:40:20 +0200
Message-ID: <NGBBLLIAMFLGJEOAJCCEOEJNDFAA.garbage_collector@telia.com>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
In-Reply-To: <OF38FCE2FD.7A284374-ONC1256DC6.00335ADD@icos.be>
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165

> From: erik dot cumps at icos in belgium
> Sent: Tuesday, October 21, 2003 11:36 AM

 Hmm... email-address visible; you ought to conceal it a bit more. Otherwise
you'll eventually end up receiving spam.
 It has started over here :-7

> Hi guys,
>
> sorry if this thread was dead but couldn't resist.
> Besides, it makes the start of my workday just that
> more bearable... :) (regular expressions for fun and
> profit eh)

LOL =-) a geek apears...

> Simply sed:
>
>     sed     's#^ *\(.*[^ ]\) */ *\(.*[^ ]\) *$#.\1.\2.#'

Hannu:
>> 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.

 Yours seems very much like mine :-) - thanks for verifying it!

I feel a bit uncertain about the need for ^ and $ being present, even as I
don't expect the string to be in the middle of something. (It appears on a
single line, with a distinct marker like 'keyword:' at the beginning.)

 As it is in my version:
's- *' will match(skip) any leading spaces,
as will ' */ *' in the middle.
Both '(.*[^ ])' -parts will grab as much nonspace text as possible,
and then the ending ' *$-' will skip spaces before hitting the end of the
string.

My simple tests indicate it does work without ^ and $ too. Should I expect
it not to, under some circumstances that I haven't thought of?

> HTH,
> Erik

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

- Raw text -


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