Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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" To: Subject: RE: OT: Using sed - guru help wanted. Date: Wed, 22 Oct 2003 21:40:20 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal In-Reply-To: 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/