The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
grep unix.com with google



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-30-2009
Registered User
 

Join Date: Aug 2009
Posts: 9
Replace blank spaces with semicolon - text file

Hi all,

Been trying to find a solution to this, I'm sure its a sed 1 liner, but I don't know sed well enough to work it out...

I have a text file in the following format:


Code:
              431        666           1332           2665          0.24395
              432        670           1340           2681          0.24544
              433        674           1349           2697          0.24693
              434        678           1357           2714          0.24844
              435        683           1365           2730          0.24995
              436        687           1373           2747          0.25148
              437        691           1382           2763          0.25300
              438        695           1390           2780          0.25454

etc....

there are a number of blank spaces between the columns, and I want to replace these blank spaces so that there is one single semi colon there instead. Any thoughts?

Thanks

Jon
  #2 (permalink)  
Old 11-30-2009
Moderator
 

Join Date: Feb 2007
Location: The Netherlands
Posts: 4,670
Much easier with awk:


Code:
awk '{$1=$1}1' OFS=";" file

  #3 (permalink)  
Old 11-30-2009
Registered User
 

Join Date: Nov 2009
Posts: 39
there's a number of different ways you can do this, one example is cut/paste
cut f1 file > tmp1; cut f2 file > tmp2; cut f3 file > tmp3; etc etc
paste tmp1 tmp2 tmp3 tmp4 > file
rm -f tmp*

something like that, 'man cut' for more info.

also grep, awk, some cool loops, input field seperator... etc
  #4 (permalink)  
Old 11-30-2009
Registered User
 

Join Date: Aug 2009
Posts: 9
Franklin, brilliant, thats exactly what I need, thanks!
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing blank spaces, tab spaces from file NARESH1302 Shell Programming and Scripting 3 08-07-2009 12:18 PM
Remove blank spaces in a text file... bhagya2340 Shell Programming and Scripting 4 03-01-2009 02:47 AM
how to remove blank spaces of a file with awk?? pabloli150 Shell Programming and Scripting 4 02-26-2009 04:08 PM
Replace blank spaces by single tab, and right alignment Jae Shell Programming and Scripting 1 08-08-2007 11:58 PM
Removing blank spaces from a file? dfs Shell Programming and Scripting 4 05-22-2007 06:59 PM



All times are GMT -4. The time now is 02:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0