?
Solved

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

Posted on 2004-03-24
6
Medium Priority
?
27,650 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:scurtis_1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10666990
Hi scurtis_1,

sed 's/ */ /g' filename


Sunnycoder
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 600 total points
ID: 10667001
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
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 10668652
As sunnycoder said, but make sure there is TWO SPACES before *

sed 's/<SPACE><SPACE>*/ /g' filename
0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 4

Assisted Solution

by:Vinit Kain
Vinit Kain earned 400 total points
ID: 10670206
hi,

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

will replace multiple white space to single space

Vinit
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10675524
being pedantic, whitespace  also contains newline and carriage return
Do you mean that too?
0
 

Author Comment

by:scurtis_1
ID: 10676399
Initially I meant just space characters but I have now included all newline and carriage return characters for my particular problem.

scott
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question