How do i remove commas(,) & spaces


 
Thread Tools Search this Thread
Operating Systems Linux How do i remove commas(,) & spaces
# 1  
Old 05-26-2008
Computer 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. Smilie
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?
# 2  
Old 05-26-2008
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
# 3  
Old 05-26-2008
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?
# 4  
Old 05-26-2008
This has been already answered by jaduks.. Check the S variable value, in jadu's post.
# 5  
Old 05-26-2008
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
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?
# 6  
Old 05-26-2008
Hey thanx a ton Jaduks, nua7 & Siba... finally it worked :-) I m very happy...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove unwanted commas from a .csv file?

how to remove unwanted commas from a .csv file Input file format "Server1","server-PRI-Windows","PRI-VC01","Microsoft Windows Server 2012, (64-bit)","Powered On","1,696.12","server-GEN-SFCHT2-VMS-R013,server-GEN-SFCHT2-VMS-R031,server-GEN-SFCHT2-VMS-R023"... (5 Replies)
Discussion started by: ranjancom2000
5 Replies

2. Shell Programming and Scripting

Remove rows containing commas with awk

Hello everyone, I have a dataset that looks something like: 1 3 2 2 3 4,5 4 3:9 5 5,9 6 5:6 I need to remove the rows that contain a comma in the second column and I'm not sure how to go about this. Here is an attempt. awk 'BEGIN {FS=" "} { if ($2!==,) print }'Any help is appreciated. (5 Replies)
Discussion started by: Rabu
5 Replies

3. Shell Programming and Scripting

Remove quotes and commas from field

In the attached file I am trying to remove all the "" and , (quotes and commas) from $2 and $3 and the "" (quotes) from $4. I tried the below as a start: awk -F"|" '{gsub(/\,/,X,$2)} 1' OFS="\t" enhancer.txt > comma.txt Thank you :). (6 Replies)
Discussion started by: cmccabe
6 Replies

4. Shell Programming and Scripting

Remove leading commas in the file

Hi , I have a file with below records 965382,10310858,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 767010,10217614,3,10217616,10217622,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,... (4 Replies)
Discussion started by: vputtas@gmail.c
4 Replies

5. Shell Programming and Scripting

remove commas if touching any letters

I have a csv file that I am trying to edit. I need to remove any comma that is touching a letter. I used this command to find them. grep , moz_places_good.csv | head -n 10 | grep ,I would think I could use some form of this to just delete the commas and not the letter before it. Just not sure... (5 Replies)
Discussion started by: cokedude
5 Replies

6. Shell Programming and Scripting

Unix remove white spaces/tabs before & after pattern

Hi All, I wanted to know is there any way we can remove white spaces/tabs before & after some pattern { eg. before & after "," }. Please find below sample data below, Sat Jul 23 16:10:03 EDT 2011 , 12345678 , PROD , xyz_2345677 , testuuyt , ... (3 Replies)
Discussion started by: gr8_usk
3 Replies

7. Shell Programming and Scripting

Remove duplicate commas after exporting excel file to csv

Hello everyone I'm new here and this is my first post so first of all I want to say that this is a great forum and I have managed to found most of my answers in these forums : ) So with that I ask you my first question: I have an excel file which I saved as a csv. However the excel file... (3 Replies)
Discussion started by: Spunkerspawn
3 Replies

8. Shell Programming and Scripting

Help with sed and replacing white spaces with commas

Dear all, I am in a bit of a quandary. I have 400 text files which I need to edit and output in a very specific way. Here is a sample text file copied from gedit ... The columns will come out a bit messed up but when I cat <file>, it gives a table with six columns (0-28, tot lob vol, vcsf,... (6 Replies)
Discussion started by: antonz
6 Replies

9. Shell Programming and Scripting

parsing log files, removing spaces and replace with commas

Hello all i am working on a database to import log files from my systems, but i cannot seem to find the answer. I searched here for a good bit and couldnt peice together what i was looking for. I know you could do this with awk, i just dont know how. Any help would be greatly appreciated.... (6 Replies)
Discussion started by: caddyjoe77
6 Replies

10. Programming

Removing empty spaces and adding commas

I have a file which contains numbers as follows: 1234 9876 6789 5677 3452 9087 4562 1367 2678 7891 I need to remove the empty spaces and add commas between the numbers like: 1234,9876,6789,5677,3452, 9087,4562,1367,2678,7891 Can anyone tell me the command to do... (4 Replies)
Discussion started by: jazz
4 Replies
Login or Register to Ask a Question