SED: How to replace all occurances of multiple whitespace with a single whitespace?

Hi,

I have a file with a single line of text in it, but the thing generating it puts large chunks of spaces throughout the line. Is there a regex format I can use with SED to replace all of these whitespace chunks with a single space?

Thanks
Scott
scurtis_1Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sunnycoderConnect With a Mentor Commented:
above will insert single space after each char ...

sed 's/  */ /g' filename

will replace one or more space characters with a single space character (notice extra space char after first / )
0
 
sunnycoderCommented:
Hi scurtis_1,

sed 's/ */ /g' filename


Sunnycoder
0
 
HamdyHassanCommented:
As sunnycoder said, but make sure there is TWO SPACES before *

sed 's/<SPACE><SPACE>*/ /g' filename
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Vinit KainConnect With a Mentor Commented:
hi,

sed 's/[<space><tab>][<space><tab>]*/ /g' filename

will replace multiple white space to single space

Vinit
0
 
ahoffmannCommented:
being pedantic, whitespace  also contains newline and carriage return
Do you mean that too?
0
 
scurtis_1Author Commented:
Initially I meant just space characters but I have now included all newline and carriage return characters for my particular problem.

scott
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.