OT: Using sed - guru help wanted.

erik.cumps@icos.be erik.cumps@icos.be
Tue Oct 21 11:45:00 GMT 2003


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/



More information about the Cygwin mailing list