This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]