Solved

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

Posted on 2004-03-24
6
27,632 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 150 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
Industry Leaders: 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 100 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 71
has22 challenge 11 107
isEverywhere  challenge 19 85
Windows shortcut location resolution on double click open 4 52
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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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