The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help removing lines with duplicated columns yahyaaa Shell Programming and Scripting 14 05-17-2008 08:33 AM
Removing columns of a file using vi Editor DilipPanda UNIX for Dummies Questions & Answers 2 02-08-2008 04:27 AM
Remove spaces from columns jacks Shell Programming and Scripting 2 01-18-2008 10:08 AM
removing spaces sahithi_khushi Shell Programming and Scripting 2 11-03-2006 11:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-24-2007
sbasetty sbasetty is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 75
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
  #2 (permalink)  
Old 01-24-2007
sbasetty sbasetty is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 75
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 (permalink)  
Old 01-24-2007
MizzGail's Avatar
MizzGail MizzGail is offline
Registered User
  
 

Join Date: Sep 2001
Location: Syracuse, NY
Posts: 164
If you search for "remove spaces" in this forum, there are a lot of answers out there. One should work for you.
  #4 (permalink)  
Old 01-24-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,875
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 (permalink)  
Old 01-24-2007
sbasetty sbasetty is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 75
great it worked

Thanks a lot
  #6 (permalink)  
Old 01-24-2007
sbasetty sbasetty is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 75
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 (permalink)  
Old 01-24-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,875
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
Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk

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 On




All times are GMT -4. The time now is 05:42 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