Fedora Linux Support Community & Resources Center
  #1  
Old 28th March 2012, 10:36 PM
pnelsonsr Offline
Registered User
 
Join Date: Jan 2007
Location: WA
Posts: 185
windows_7ie
Using sed to change spaces to a tab

Have an output that has spaces between columns and these are not a standard amount so I would like to change them to tabs so I can cut the values out. Been trying to do it with sed with something like:

Code:
sed "s/\s+/\t/g"
But that doesn't seem to be working.

---------- Post added at 02:36 PM ---------- Previous post was at 02:30 PM ----------

Well I was trying some of the command line arguments for sed and found -r so the following now removes the white space between columns and puts a tab in its place. Here is the working sed statement:

Code:
sed -r "s/\s+/\t/g"
Reply With Quote
  #2  
Old 28th March 2012, 11:31 PM
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,696
linuxfirefox
Re: Using sed to change spaces to a tab

sed -e "s/\ /\t/g"

but tr is easier for this one

tr ' ' '\t'

---------- Post added at 06:31 PM ---------- Previous post was at 06:20 PM ----------

Oops - I misread as single space ....
sed -e 's/ [ ]*/\t/g'
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
  #3  
Old 29th March 2012, 12:50 AM
pnelsonsr Offline
Registered User
 
Join Date: Jan 2007
Location: WA
Posts: 185
windows_7ie
Re: Using sed to change spaces to a tab

stevea-> sed -e 's/ [ ]*/\t/g'

The [ ]* doesn't work as it takes 0-n which ultimately puts a tab between everything. As noted above I used the + for 1-n.

To specify white space I used /s but you can also use the set [ ] or even [[:space:]]... /s was just shorter but [ ] works as well

Alrighty I'm amazed that there are multiple ways to do it and I just didn't stumble on it at first! Thanks.

Last edited by pnelsonsr; 29th March 2012 at 12:59 AM.
Reply With Quote
  #4  
Old 29th March 2012, 05:29 AM
cazo Offline
Registered User
 
Join Date: Sep 2005
Location: Redneck Riviera
Posts: 357
linuxchrome
Re: Using sed to change spaces to a tab

Even though you have solved this, unexpand (part of coreutils) will also take care of this.
Reply With Quote
  #5  
Old 29th March 2012, 05:13 PM
pnelsonsr Offline
Registered User
 
Join Date: Jan 2007
Location: WA
Posts: 185
windows_7ie
Re: Using sed to change spaces to a tab

Quote:
Originally Posted by cazo View Post
Even though you have solved this, unexpand (part of coreutils) will also take care of this.
I tried this with unexpand -a and it did only the first space and not all the space between the text in the columns. I also tried it with --first-only and this also did not work correctly. So, I'm not sure how you use unexpand.
Reply With Quote
Reply

Tags
change, sed, spaces, tab

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Spaces Linux Nut Programming & Packaging 6 30th November 2010 06:08 AM
problem with makefile and spaces A_n_H Programming & Packaging 1 1st June 2009 08:21 PM
Work Spaces on a cube m.nassar Using Fedora 2 4th June 2008 01:57 PM
RPM/Yum: Spaces in Repo Name hellork Using Fedora 5 9th December 2007 05:13 AM
spaces in output command festhead Using Fedora 3 7th August 2007 09:59 PM


Current GMT-time: 18:50 (Tuesday, 22-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat