How to remove space from each record in file? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

How to remove space from each record in file?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-12-2013
jagdishrout jagdishrout is offline
Registered User
 
Join Date: Jun 2012
Last Activity: 5 March 2013, 6:06 AM EST
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
Last Activity: 27 September 2014, 1:33 AM EDT
Location: Mumbai, India
Posts: 1,614
Thanks: 125
Thanked 184 Times in 178 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
./hari.sh ./hari.sh is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 17 January 2014, 5:27 AM EST
Posts: 97
Thanks: 6
Thanked 4 Times in 4 Posts
Did you mean, to do in a shell script?

sed 's/ //g' MyFile
    #4  
Old 02-12-2013
kg_gaurav kg_gaurav is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 17 September 2014, 6:39 AM EDT
Posts: 45
Thanks: 3
Thanked 2 Times in 2 Posts

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

Sponsored Links
    #5  
Old 02-12-2013
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 9 September 2014, 8:08 AM EDT
Location: India
Posts: 1,412
Thanks: 101
Thanked 496 Times in 473 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
kg_gaurav kg_gaurav is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 17 September 2014, 6:39 AM EDT
Posts: 45
Thanks: 3
Thanked 2 Times in 2 Posts
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
busyboy busyboy is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 19 March 2014, 3:51 AM EDT
Posts: 191
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
Closed Thread

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 07:57 PM.