sed - substituting multiple occurrances of whitespace with a ':'
Hi All
I'm having a few problems removing multiple occurrance of whitespace with a ':'. Here's the string: Code:
8 contact_name jsmith Code:
8:contact_name:cralph
I've tried: Code:
cat userlist | sed -e 's/[ ]/:/' Code:
cat userlist | sed -e 's/[ ]/:/g' TIA, Simplified |
Hi,
Is this what you're looking for: sed -e 's/[[:space:]][[:space:]]*/:/g' -e 's/^://' infile Replaces all sorts of whitespaces (and removes the leading one). Hope this helps. |
Druuna - you are the man!! Thanks a million :D
|
Consider also:
[[:blank:]] (removes tabs also) |
Hi,
For clarity: [[:blank:]] -> spaces and tabs only (!) [[:space:]] -> all (!) whitespace chars. |
Quote:
If it's just spaces (no tabs) this should work Code:
cat userlist | sed 's/ \{1,\}/:/g' Code:
cat userlist | sed 's/[ \t]\{1,\}/:/g' |
@vonbiber: You are forgetting the removal of the leading whitespace..... Thread was already solved as well.
|
Quote:
Why do I think that is counter-intuitive? Other than a newline, what is whitespace that is not a space or a tab? |
@pixellany: Besides the space and (horizontal) tab it also removes vertical tabs and formfeeds.
[ \t\r\n\v\f] == [[:space::]] [ \t] == [[::blank::]] I can understand the confusion :) |
All times are GMT -5. The time now is 04:37 AM. |