The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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
How to remove trailing spaces mahek_bedi UNIX for Dummies Questions & Answers 2 08-10-2007 04:21 AM
Removing empty spaces and adding commas jazz High Level Programming 4 11-13-2006 06:54 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 05-25-2008
Registered User
 

Join Date: May 2008
Posts: 51
Talking How do i remove commas(,) & spaces

Hey guys,
I am very much new to shell scripts. So you ppl may feel that i am asking stupid question here.
1. I am using command line argument as an input variable. The user gets this value in his mail from client which has commas n spaces (Eg. 12,34,56,789) and the scripts input should not contain any commas, spaces dashes etc... So to Normalise it i hv used following thing

sh 123.sh 12,34,56,789
#12,34,56,789 is jst an example of input i.e. command line argument.
echo "$1" | perl -pi -e "s/,//g;"

Now the problem is I want to take its output (i.e output of echo "$1" | perl -pi -e "s/,//g;" ) as input for next line of script. For this I tried following thing

echo "$1" | perl -pi -e "s/,//g;" | $i

But its not working... what do i do?
Reply With Quote
Forum Sponsor
  #2  
Old 05-25-2008
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: Assam,India
Posts: 146
Code:
echo $1 | sed 's/,//g'
should work.

And you can assign that like this

Code:
S=`echo $1 | sed 's/,//g'`
Hope it answers your query.

//Jadu
Reply With Quote
  #3  
Old 05-25-2008
Registered User
 

Join Date: May 2008
Posts: 51
Hey Thanx for the quick reply
The line written by me in script (i.e echo "$1" | perl -pi -e "s/,//g;") even that is working... but what i want to do is, i want to take the output of this line in a variable... So that i can use it further.. Do u kno how do i do it?
Reply With Quote
  #4  
Old 05-25-2008
Registered User
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 352
This has been already answered by jaduks.. Check the S variable value, in jadu's post.
Reply With Quote
  #5  
Old 05-25-2008
Registered User
 

Join Date: Jun 2007
Posts: 50
var1=`echo $1 | tr "," " "`
If $1 = 1,2,3
Then var1 will contain 1 2 3.

Thanks & Regards,
Siba


Quote:
Originally Posted by anushree.a View Post
Hey Thanx for the quick reply
The line written by me in script (i.e echo "$1" | perl -pi -e "s/,//g;") even that is working... but what i want to do is, i want to take the output of this line in a variable... So that i can use it further.. Do u kno how do i do it?
Reply With Quote
  #6  
Old 05-25-2008
Registered User
 

Join Date: May 2008
Posts: 51
Hey thanx a ton Jaduks, nua7 & Siba... finally it worked :-) I m very happy...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:46 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