delorie.com/archives/browse.cgi | search |
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 |
To: | <cygwin AT cygwin DOT com> |
Subject: | RE: OT: Using sed - guru help wanted. |
Message-ID: | <OF38FCE2FD.7A284374-ONC1256DC6.00335ADD@icos.be> |
From: | erik DOT cumps AT icos DOT be |
Date: | Tue, 21 Oct 2003 11:36:01 +0200 |
MIME-Version: | 1.0 |
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) Simply sed: sed 's#^ *\(.*[^ ]\) */ *\(.*[^ ]\) *$#.\1.\2.#' Simply perl: perl -pe 's/^\s*(.*\S)\s*\/\s*(.*\S)\s*$/.$1.$2./' Both will split at the slash and strip leading/trailing spaces from the parts, even if a part contains just a single non-whitespace character, even if there is no whitespace to remove. Simple explanation: at start of string; zero or more spaces; string of zero or more characters; non-space character; zero or more spaces; slash; zero or more spaces; string of zero or more characters; non-space character; zero or more spaces; at end of string. HTH, Erik 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. -- 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/ -- 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/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |