This is the mail archive of the
mailing list for the Cygwin project.
RE: OT: Using sed - guru help wanted.
- From: "Hannu E K Nevalainen" <garbage_collector at telia dot com>
- To: <cygwin at cygwin dot com>
- Date: Wed, 22 Oct 2003 21:40:20 +0200
- Subject: RE: OT: Using sed - guru help wanted.
> 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.#'
>> 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
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?
/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