something unclear with sed for me

2005-05-11 Thread Andras Lorincz
I want to replaces all multiple spaces with one space. My first
attempt was this:

sed -e 's/\ */\ /g'

This replaced all multiple spaces with one but as a side effect, sed
inserted a space between all characters. Playing a little I tried
this:

sed -e 's/[\ ]\ */\ /g'

and this works. The fact is that I don't understand why the first one
doesn't work. Can someone explain me that?



Re: something unclear with sed for me

2005-05-11 Thread David Jardine
On Wed, May 11, 2005 at 03:01:47PM +0300, Andras Lorincz wrote:
 I want to replaces all multiple spaces with one space. My first
 attempt was this:
 
 sed -e 's/\ */\ /g'

The asterisk means zero or more, so it matches evven if there are 
no spaces.

 
 This replaced all multiple spaces with one but as a side effect, sed
 inserted a space between all characters. Playing a little I tried
 this:
 
 sed -e 's/[\ ]\ */\ /g'
 
 and this works. The fact is that I don't understand why the first one
 doesn't work. Can someone explain me that?
 

-- 
David Jardine

Running Debian GNU/Linux and
loving every minute of it.  -L. von Sacher-M.(1835-1895)


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



RE: something unclear with sed for me

2005-05-11 Thread Cho Wooyoung
 From: Andras Lorincz [mailto:[EMAIL PROTECTED] 
 
 I want to replaces all multiple spaces with one space. My 
 first attempt was this:
 
 sed -e 's/\ */\ /g'
 
 This replaced all multiple spaces with one but as a side 
 effect, sed inserted a space between all characters. Playing 
 a little I tried
 this:
 
 sed -e 's/[\ ]\ */\ /g'
 
 and this works. The fact is that I don't understand why the 
 first one doesn't work. Can someone explain me that?
 

You can use + that means one or more of the preceding character. But + is
defined in extended regular expression. use -r option for the extended
regular expression like this:

sed -r 's/ +/ /g'


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: something unclear with sed for me

2005-05-11 Thread Kamaraju Kusumanchi
Andras Lorincz wrote:
I want to replaces all multiple spaces with one space. My first
attempt was this:
sed -e 's/\ */\ /g'
This replaced all multiple spaces with one but as a side effect, sed
inserted a space between all characters. Playing a little I tried
this:
sed -e 's/[\ ]\ */\ /g'
and this works. The fact is that I don't understand why the first one
doesn't work. Can someone explain me that?
I dont know about sed. But you can do this with the tr command.
tr -s ' '   is what you are after. For more details see man tr.
raju
--
Graduate student
MAE, Cornell University
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: something unclear with sed for me

2005-05-11 Thread Phil Dyer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Andras Lorincz wrote:
 I want to replaces all multiple spaces with one space. My first
 attempt was this:
 
 sed -e 's/\ */\ /g'
 
 This replaced all multiple spaces with one but as a side effect, sed
 inserted a space between all characters. 

You told sed replace 0 or more whitespace characters with 1 whitespace
character.

 
 sed -e 's/[\ ]\ */\ /g'
 
 and this works. The fact is that I don't understand why the first one
 doesn't work. Can someone explain me that?

This time you told sed  replace 1 or more whitespace characters with 1
whitespace character.


- --

/phil


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.0 (MingW32)
Comment: Public Key: http://www.dyermaker.org/gpgkey

iD8DBQFCgkw/Gbd/rBLcaFwRAtUqAKCu8C+iNH53011Lq3NGX680H/P4xwCdGUBZ
e78WXTGi3RGpm3uoGFBv04I=
=ZkNQ
-END PGP SIGNATURE-


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]