> From: Brian Dessent > Sent: Monday, October 20, 2003 10:43 PM > 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.!'
Thanks a lot! Now all I have to do is understand where the difference is ;-7 $ echo ' a b / c d e ' | \ sed -re 's!^ +(.*) +/ +(.*?) +$!.\1.\2.!' .a b.c d e. It seems as the -r flag to sed made _this_ expression work right OOTB. Hmm... lets see; $ echo ' a b / c d e ' | sed -e 's/^ \+\(.*\) \+\/ \+\(.*\) \+$/.\1.\2./' .a b.c d e. So THERE was the problem, some escaping needed. 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. /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/