Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-12-2013
Registered User
 
Join Date: Jun 2012
Location: bangalore
Posts: 8
Thanks: 5
Thanked 0 Times in 0 Posts
How to remove space from each record in file?

Hi ,
I want to remove space from each record in one file My file is like

Code:
BUD, BDL 
ABC, DDD, ABC
ABC, DDD, DDD, KKK

The o/p should be

Code:
BUD,BDL 
ABC,DDD,ABC
ABC,DDD,DDD,KKK

Can any one help me regarding this?

Last edited by Franklin52; 02-12-2013 at 08:40 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old 02-12-2013
clx clx is offline Forum Advisor  
Registered User
 
Join Date: Jun 2007
Location: Mumbai,India
Posts: 1,420
Thanks: 101
Thanked 133 Times in 129 Posts
If you want to remove space anywhere in the file.


Code:
sed 's/[ ]//g' file

The Following User Says Thank You to clx For This Useful Post:
jagdishrout (02-12-2013)
Sponsored Links
    #3  
Old 02-12-2013
./hari.sh's Avatar
Registered User
 
Join Date: Jul 2007
Posts: 95
Thanks: 5
Thanked 4 Times in 4 Posts
Did you mean, to do in a shell script?

sed 's/ //g' MyFile
    #4  
Old 02-12-2013
Registered User
 
Join Date: Feb 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post

Code:
cat temp |sed 's/, /,/g'>newtemp

Sponsored Links
    #5  
Old 02-12-2013
elixir_sinari's Avatar
Gotham Knight
 
Join Date: Mar 2012
Location: India
Posts: 1,396
Thanks: 91
Thanked 490 Times in 468 Posts

Code:
tr -d ' ' < infile > outfile

@kg_gaurav, would you elaborate on the significance of using cat in your pipeline?
Sponsored Links
    #6  
Old 02-12-2013
Registered User
 
Join Date: Feb 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
Quote:
Originally Posted by elixir_sinari View Post
Code:
tr -d ' ' < infile > outfile

@kg_gaurav, would you elaborate on the significance of using cat in your pipeline?

i considered all data like
BUD, BDL
ABC, DDD, ABC
ABC, DDD, DDD, KKK

are in file temp. so cat that and pipped with sed. well i usually use pipe you may directely use

Code:
sed 's/, /,/g' temp >newfile

Sponsored Links
    #7  
Old 02-12-2013
Registered User
 
Join Date: Jan 2010
Posts: 185
Thanks: 2
Thanked 9 Times in 9 Posts

Code:
awk '{ gsub(/,[ ]/,",",$0); print }' file


Last edited by Franklin52; 02-12-2013 at 08:40 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To remove a particular record from File SatishW Shell Programming and Scripting 5 01-06-2010 02:07 PM
Remove particular record from a file devmns Shell Programming and Scripting 4 10-07-2009 03:11 AM
To remove the record from a file laxmi131 UNIX for Advanced & Expert Users 1 12-17-2008 06:54 AM
How to remove a particular record from a file? kanu_pathak Shell Programming and Scripting 9 07-22-2008 09:34 AM
Remove First and Last Record from a file ravikuc UNIX for Dummies Questions & Answers 1 10-11-2007 03:35 AM



All times are GMT -4. The time now is 03:59 AM.