Whitespace in SED

  • Follow


I thought that \s was for whitespace, but the following does not seem to
work.  What am I missing?

s/^ \*\s*defin/ *  Defin/I

I'm trying to fix the following comment block in some code.  I want to force
two spaces between the asterisk and the initial "d", as well as convert the
"d" to uppercase.  The spacing could be a combination of spaces or tabs (ie.
whitespace).  The word "defining" could also be "define".

 *         defining buffer lengths


0
Reply fmankal (2) 1/8/2004 6:42:04 PM


frank wrote:
> I thought that \s was for whitespace, but the following does not seem to
> work.  What am I missing?

The sed NG perhaps ;-) ?

> s/^ \*\s*defin/ *  Defin/I
> 
> I'm trying to fix the following comment block in some code.  I want to force
> two spaces between the asterisk and the initial "d", as well as convert the
> "d" to uppercase.  The spacing could be a combination of spaces or tabs (ie.
> whitespace).  The word "defining" could also be "define".
> 
>  *         defining buffer lengths
> 

This will work:

sed 's/^ \*[ 	]*[dD]efin/ *  Defin/'

where there's a single blank followed by a single tab within the first 
square brackets. For general white-space, look at the [:space:] 
construct in GNU sed.

	Ed.

0
Reply Ed 1/8/2004 7:02:26 PM


frank wrote:
> I thought that \s was for whitespace, but the following does not seem to
> work.  What am I missing?
> 
> s/^ \*\s*defin/ *  Defin/I
> 
> I'm trying to fix the following comment block in some code.  I want to force
> two spaces between the asterisk and the initial "d", as well as convert the
> "d" to uppercase.  The spacing could be a combination of spaces or tabs (ie.
> whitespace).  The word "defining" could also be "define".
> 
>  *         defining buffer lengths
> 
sed doesn't understand the \(letter) codes in regular expressions.
Use perl instead.

                Chris Mattern

0
Reply Chris 1/8/2004 8:35:07 PM

2 Replies
138 Views

(page loaded in 0.04 seconds)

Similiar Articles:













7/8/2012 8:23:01 AM


Reply: