[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-03-24
6
Medium Priority
?
27,663 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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

826 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