Results 1 to 3 of 3
I have following line
hello world world hello world
I am able to delete one space using following
sed 's/[ \t]//g'
and more than one space beginning of the line
...
- 04-11-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 19
How to delete one/more space using sed
I have following line
hello world world hello world
I am able to delete one space using following
sed 's/[ \t]//g'
and more than one space beginning of the line
sed 's/[ \t]*//g'
but when I doing this for replacing one or more space ":" in line
sed 's/[ \t]*//g'
getting following output
h:e:l:l:o:w:o:r:l:d:w:o:r:l:d:h:e:l:l:o
instead of
hello:world:world:hello:world:
please suggest
thanks
- 04-13-2008 #2Linux Enthusiast
- Join Date
- Apr 2004
- Location
- UK
- Posts
- 658
I'm pretty sure you posted the second code snippet twice.
* means match "none or more" so your pattern will happily match nothing and insert a colon.
You'd want to use a + to indicate "one or more"
If this doesn't work for you, remove the \ before the +. For some reason I had to escape it when I'm pretty sure I shouldn't need to.Code:echo "hello world world hello world" | sed 's/[ \t]\+/:/g' hello:world:world:hello:world
Let us know how you get on,
Chris...To be good, you must first be bad. "Newbie" is a rank, not a slight.
- 04-13-2008 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
working with fields is much easier
Code:# echo "hello world world hello world" | awk '{$1=$1}1' OFS=":" hello:world:world:hello:world


Reply With Quote