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

  Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

How to remove space from each record in file?

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 02-12-2013
clx clx is offline Forum Advisor  
Registered User
 
Join Date: Jun 2007
Last Activity: 22 July 2016, 6:01 AM EDT
Location: Mumbai, India
Posts: 1,688
Thanks: 138
Thanked 204 Times in 198 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 Unix and Linux 02-12-2013
./hari.sh's Unix or Linux Image
./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 Unix and Linux 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 Unix and Linux 02-12-2013
elixir_sinari's Unix or Linux Image
elixir_sinari elixir_sinari is offline Forum Advisor  
Registered User
 
Join Date: Mar 2012
Last Activity: 22 July 2016, 6:46 AM EDT
Location: India
Posts: 1,413
Thanks: 101
Thanked 497 Times in 474 Posts

Code:
tr -d ' ' < infile > outfile

@kg_gaurav, would you elaborate on the significance of using cat in your pipeline?
Sponsored Links
    #6  
Old Unix and Linux 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 Unix and Linux 02-12-2013
busyboy busyboy is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 12 October 2015, 9:15 AM EDT
Posts: 193
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 Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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:47 AM.