Removing blank spaces from a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing blank spaces from a file?
# 1  
Old 05-22-2007
CPU & Memory Removing blank spaces from a file?

Guys, I need some help... how can I remove the blank spaces between the lines below? (between the date and the hour fields)
Code:
21/05/07        00:05:00 99
21/05/07        00:10:01 99
21/05/07        00:15:00 99
21/05/07        00:20:00 99
21/05/07        00:25:00 99

I want to make the file look like:
Code:
21/05/07 00:05:00 99
21/05/07 00:10:01 99
21/05/07 00:15:00 99
21/05/07 00:20:00 99
21/05/07 00:25:00 99

Removing the blank spaces and leaving only one blank space between the columns. Is it possible to do that using awk or sed ?

Thanks a lot!

Last edited by dfs; 05-22-2007 at 04:20 PM..
# 2  
Old 05-22-2007
modifying your input file as below !

Code:
21/05/07   00:05:00 99
21/05/07   00:10:01 99
21/05/07   00:15:00 99
21/05/07  00:20:00 99
21/05/07     00:25:00 99


Code:
sed 's/  */ /g' filename

there are two spaces in the search block,
<space><space>*
# 3  
Old 05-22-2007
CPU & Memory

matrix, thanks for the answer, but I just noticed that the blank space was created using TAB, how do I do remove that ?

Thanks a lot!
# 4  
Old 05-22-2007
Code:
awk '$1=$1' infile

Use nawk on Solaris.
# 5  
Old 05-22-2007
MySQL

thanks a lot guys! I got it working with your tips!

Thanks again!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Removing blank/white spaces and special characters

Hello All , 1. I am trying to do a task where I need to remove Blank spaces from my file , I am usingawk '{$1=$1}{print}' file>file1Input :- ;05/12/1990 ;31/03/2014 ; Output:- ;05/12/1990 ;31/03/2014 ;This command is not removing all spaces from... (6 Replies)
Discussion started by: himanshu sood
6 Replies

3. Emergency UNIX and Linux Support

Removing ONLY UNIQUE blank spaces with sed?

Hi, I have data that looks similar to this: In which the sentences are written horizontally and the beginning of a sentence is indicated by a 1 in the first column and the number increments until the last item of the sentence. The end of the sentence and the beginning of the next is then indicate... (1 Reply)
Discussion started by: owwow14
1 Replies

4. Shell Programming and Scripting

How to remove all blank spaces in a file

I have a file which contains data such as that shown below. How do i remove all the blcnak spaces, before, during and at the end of each line in one command? 300015, 58.0823212, 230.424728 300016, 58.2276459, 229.141602 300017, 58.7590027, 226.960846 ... (9 Replies)
Discussion started by: carlr
9 Replies

5. Solaris

Removing blank spaces

Hi , I want to go out of vi editor temporarily and execute a command in command prompt and again going back to the editor . Is it possible . Any help on this is really helpful. 1. Need to open vi 2. Temporarily come out and execute a command and go back to vi editor (6 Replies)
Discussion started by: rogerben
6 Replies

6. 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

7. Shell Programming and Scripting

removing blank spaces in a script

Hi I am writing a shell to run sqlplus scripts. i found a issue in my scripts that oracle will not spool a file if there is blank spaces in the word like /backup dir/scriptrelease/1_DDL or /backupdir/script release/2_DDL can we write some thing in the shell to make "/backup dir" to... (1 Reply)
Discussion started by: srichunduru
1 Replies

8. 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

9. 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

10. 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
Login or Register to Ask a Question