[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RE: something unclear with sed for me



> From: Andras Lorincz [mailto:andras.lorincz@gmail.com] 
> 
> 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'



Reply to: