The UNIX and Linux Forums  

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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do i remove commas(,) & spaces anushree.a Linux 5 05-25-2008 11:39 PM
remove spaces btw tjmannonline UNIX for Dummies Questions & Answers 7 05-25-2008 11:35 PM
Remove spaces from columns jacks Shell Programming and Scripting 2 01-18-2008 07:08 AM
need help to remove spaces from first column tayyabq8 Shell Programming and Scripting 4 01-28-2006 01:40 AM
how to remove spaces in a string using sed. radhika Shell Programming and Scripting 4 06-02-2005 12:00 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-10-2008
Registered User
 

Join Date: Jun 2008
Posts: 12
Remove spaces between charc and replace it with ','.

Hi,

Below is my output file: (The below line has multiple spaces bet charc and I want to replace spaces with "," only for the first line)

NYCCMS97KJ931 01-JUN-08 1214957



I want this to be:

NYCCMS97KJ931, 01-JUN-08, 1214957


Thanks in advance.
Reply With Quote
Forum Sponsor
  #2  
Old 06-10-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
sed "1s/ /, /g" input_file.txt
Reply With Quote
  #3  
Old 06-10-2008
Registered User
 

Join Date: Jun 2008
Posts: 12
This is showing my output like:

NYCCMS97KJ931, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , 01-JUN-08, , , , 1214957


I just want to replace all the spaces with one ",".

Thanks.
Reply With Quote
  #4  
Old 06-10-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
sed "1s/  */, /g" input_file.txt
Reply With Quote
  #5  
Old 06-10-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,196
Code:
tr ' ' ','
or
Code:
sed 's/ /,/g'
or
Code:
awk '{gsub(" ",",")}1'
Reply With Quote
  #6  
Old 06-10-2008
Registered User
 

Join Date: Jun 2008
Posts: 12
Thanks it worked.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0