This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
RE: OT: Using sed - guru help wanted.
- From: erik dot cumps at icos dot be
- To: <cygwin at cygwin dot com>
- Date: Tue, 21 Oct 2003 11:36:01 +0200
- Subject: RE: OT: Using sed - guru help wanted.
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/