Replace blank spaces with semicolon - text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace blank spaces with semicolon - text file
# 1  
Old 11-30-2009
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  
Old 11-30-2009
Much easier with awk:

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

# 3  
Old 11-30-2009
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  
Old 11-30-2009
Franklin, brilliant, thats exactly what I need, thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add Blank Spaces in text, to perform beter alignment of the string

Hi Guru, I need some advice on how to add blank spaces to the code, rather than me just adding <space-bar spaces> which does not work. Current output of the code File System Backed Up - ALL_LOCAL_DRIVES Daily - Incremental Backup Schedule - 1 Month Retention • 7pm - PRD... (2 Replies)
Discussion started by: Junes
2 Replies

2. Shell Programming and Scripting

Replace semicolon within double quotes in a file with semicolon delimiter

Hello Team, Could you please help me with the below question? I have a file with the following properties 1) File Delimiter is ; 2) Text columns are within double quotes 3) Numeric columns will not have double quotes 4) File has total 6 columns Please see a sample record from file ... (3 Replies)
Discussion started by: sam99
3 Replies

3. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

4. Shell Programming and Scripting

Help with removal of blank spaces in a file

Hello.. I have a text file. I want to remove all the blank spaces(except tab) from the file.. I tried using sed command as shown below sed 's/ //g' file1 But the problem with the above command is that it also eliminates 'tab' which is between the columns.. For example if the contents... (7 Replies)
Discussion started by: abk07
7 Replies

5. Shell Programming and Scripting

how to remove blank spaces in file

hi i have a file which store some data.the contents of my file is data1:data2 data3:data4 i have a script which read this file correct="$(cat /root/sh | cut -d: -f1)" i used this syntax..please help me which syntax is used to remove blank spaces..then how to read this file.. (1 Reply)
Discussion started by: shubhig15
1 Replies

6. UNIX for Dummies Questions & Answers

Removing blank spaces from text files in UNIX

Hello, I am an super newbie, so forgive my sheer ignorance. I have a series of text files formatted as follows (just showing the header and first few lines): mean_geo mean_raw lat lon 0.000 0 -70.616 163.021 0.000 0 -70.620 163.073 0.000 ... (8 Replies)
Discussion started by: vtoniolo
8 Replies

7. Shell Programming and Scripting

Blank spaces missing in the file

I have a file which has blank spaces($) and the blank spaces at the end of the file are not coming up while cutting the files.. please find the following file, desired output.. file1: 001_AHaris$$$$$020$$$$$$$$$ 001_ATony$$$$$$030$$$$$$$$$ 002_AChris$$$$$090$$$$$$$$$... (5 Replies)
Discussion started by: techmoris
5 Replies

8. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

9. Shell Programming and Scripting

Remove blank spaces in a text file...

Hi, I have this problem that there are blank spaces in my text file... i want to remove them line 1 line 2 line 3 I want to remove the space between line 2 and line 3... I tried sed... it work but it prints the whole text file at the command prompt which i dont want.... sde i tried was... (4 Replies)
Discussion started by: bhagya2340
4 Replies

10. Shell Programming and Scripting

Replace blank spaces by single tab, and right alignment

Folks, I am wondering if anyone solve this problem. What I want to know is, 1. Delete all white spaces including leading blank space in each line (e.g. line 2), and replace such spaces by single tab except leading blank space 2. Then, align all columns to the right. But, output white space... (1 Reply)
Discussion started by: Jae
1 Replies
Login or Register to Ask a Question