removing spaces betweent columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing spaces betweent columns
# 1  
Old 01-24-2007
removing spaces betweent columns

Hello Friends,

Can any one help me with this issue:

I would like to format a file:

say if I have rows like:

4512 , SMITH , I-28984 ,, 4324 , 4343
42312 , SMITH , I-2EE8984 ,, 432E4E4 , 4343


I would like to have the output diaplayed like :
4512 ,SMITH,I-28984,,4324, 4343
42312, SMITH, I-2EE8984 ,,432E4E4,4343


Thanks in advance for your help

Sam Smilie
# 2  
Old 01-24-2007
I have tried using

cat file_name.txt | tr -s " " ","

this is overwriting the blank spaces


S1234, A98 76 , A6789 , , , , A5677 , 3452
S9087 , A4562 , A1367 , A2678 , D7891

Displays:
S1234,A98,76,A6789,A5677,3452
S9087,A4562,A1367,A2678,D7891


It should be:

S1234,A98 76,A6789,,,,A5677,3452
S9087,A4562,A1367,A2678,D7891


Thanks
# 3  
Old 01-24-2007
If you search for "remove spaces" in this forum, there are a lot of answers out there. One should work for you.
# 4  
Old 01-24-2007
Quote:
Originally Posted by sbasetty
[...]
I would like to format a file:

say if I have rows like:

4512 , SMITH , I-28984 ,, 4324 , 4343
42312 , SMITH , I-2EE8984 ,, 432E4E4 , 4343


I would like to have the output diaplayed like :
4512 ,SMITH,I-28984,,4324, 4343
42312, SMITH, I-2EE8984 ,,432E4E4,4343
[...]

Code:
awk '$1=$1' OFS= infile # use nawk on Solaris

# 5  
Old 01-24-2007
great it worked

Thanks a lot
# 6  
Old 01-24-2007
with this command it is cupressing all spaces,
I would like to have format something like this


if input has:

4545, SMITH MICHAEL ,584 Parkview , MD


It should display
4545,SMITH MICHAEL,584 Parkview,MD


Thank you
# 7  
Old 01-24-2007
Quote:
Originally Posted by sbasetty
with this command it is cupressing all spaces,
I would like to have format something like this


if input has:

4545, SMITH MICHAEL ,584 Parkview , MD


It should display
4545,SMITH MICHAEL,584 Parkview,MD
Code:
awk '{gsub(/ *, */,",")}1' infile

sed 's/ *, */,/g' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing blanks, spaces

I have pipe separated file with lots of blank spaces. After using sed -e 's/ *| */|/g' this command ,its giving me output as TT0000013101640| HCAMBLAMCNB010|Jul 3 2012 11:14AM| HARYANA| Bangali Mohalla | TCL-UBR|9368040005|9355264655|9218509220|NULL ... (5 Replies)
Discussion started by: sususa
5 Replies

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

3. UNIX for Dummies Questions & Answers

Removing columns from a text file that do not have any values in second and third columns

I have a text file that has three columns. But at the end of the text file, there are trailing lines that have missing second and third columns: 4 0.04972604 KLHL28 4 0.0497332 CSTB 4 0.04979822 AIF1 4 0.04983331 DECR2 4 0.04990344 KATNB1 4 4 4 4 How can I remove the trailing... (3 Replies)
Discussion started by: evelibertine
3 Replies

4. Shell Programming and Scripting

awk for removing spaces

HI, I have a file with lot of blank lines, how can I remove those using awk?? Thanks, Shruthi (4 Replies)
Discussion started by: shruthidwh
4 Replies

5. Shell Programming and Scripting

removing spaces in filenames

I have a problem mounting images because of the spaces in the filenames. Does anyone know how to rename files by removing the spaces with the find command? find Desktop/$dir -name "*.dmg" -print -exec ??? (4 Replies)
Discussion started by: ianebaj
4 Replies

6. Shell Programming and Scripting

Removing spaces within Filename

Hello, I have a Folder (myfile) which contain the following files: P$12789865KR +N+01+OM+16102009165416.nu P$M1-508962GD +N+01+ALP+14102009094417.nu Is there a sed command(s) that will loop through this folder and remove the spaces that exists in the filename? Any help would be... (7 Replies)
Discussion started by: Fishn
7 Replies

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

8. UNIX for Dummies Questions & Answers

Removing spaces...

Hey, I'm using the command from this thread https://www.unix.com/unix-dummies-questions-answers/590-converting-list-into-line.html to convert vertical lines to horzontal lines. But I need to remove the spaces that is created. Unfortunately I can't figure out where the space is in the code.. I... (2 Replies)
Discussion started by: lost
2 Replies

9. Shell Programming and Scripting

removing spaces

hey.. i had a problem with the unix command when i want to remove the white spaces in a string..i guess i cud do it with a sed command but i get an error when i give space in the square brackets.. string="nh hjh llk" p=`echo $string | sed 's/ //g'` i donno how to give space charater and... (2 Replies)
Discussion started by: sahithi_khushi
2 Replies

10. Shell Programming and Scripting

removing spaces after sperator

Hi friends i have problem 6000000001| CDC049| 109| CDC| 02/02/2006| Auto| New Add| 02/03/2006 6000000002| CDC033| 109| CDC| 02/02/2006| Auto| New Add| 02/03/2006 6000000003| CDC037| 109| CDC| 02/02/2006| Auto| New Add| 02/03/2006 6000000004| CDC031| ... (6 Replies)
Discussion started by: vishnu_vaka
6 Replies
Login or Register to Ask a Question