Remove comma from decimal value using sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove comma from decimal value using sed command
# 1  
Old 06-26-2011
Remove comma from decimal value using sed command

Hi Experts ,

My requirement is like this ..
I have source comming as 4,234.55
I need and out put = 4234.55
I need to write a sed command ..

I have already used sed command for multiple conditions in a file for replacing comma , double quotes , brackets , retain negative values..
but not able to remove comma for decimal value

Can the code be embeded with the same sed command
Any help would be appreciated

My sed command as of now is this below
sed -e 's/\("[^,]*\)[,]\([^"]*"\)/\1\2/g' test | sed -e ':a' -e 's/\("[^"][^"]*\),\([^"][^"]*"\)/\1\2/;ta' | sed 's/"//g' | sed 's/(\([0-9.][0-9.]*,\{0,1\}[0-9]*\))/-\1/g' > sample

Thanks
# 2  
Old 06-26-2011
Removes comma between two decimal digits:
Code:
sed 's/\([0-9]\),\([0-9]\)/\1\2/g'

# 3  
Old 06-26-2011
Thanks yazu
# 4  
Old 06-27-2011
$ echo "4,234.55" | sed 's,\,,,g'
4234.55
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or revelent command to remove car

How to remove the digits. I need to check after / if I have more the 3 digit remove all including backslash Input file portshow 8/150800 portshow 9/150900 portshow 12/150c00 portshow 12/150 portshow 15/150f00 portshow 16/151000 portshow 17/151100 portshow 17/15... (6 Replies)
Discussion started by: ranjancom2000
6 Replies

2. Shell Programming and Scripting

How to remove comma?

hi all, in the 3rd field i am having comma. can anyone tell me how to remove the comma in the 3rd field and 4th field. |1.77|0.1|1,335.20|3,513.30|190|7.00 |4.40 |2.50 |1|1|5|5|Section903-Liquor|StLouis|0||||||||||| 40997|9999999|9999999|195186280|0102796|36949|00083089660358|2016|MAY ... (2 Replies)
Discussion started by: arun888
2 Replies

3. Shell Programming and Scripting

sed command to remove a word from string

Hello All, I am running a command find . -name amp.cfg | cut -c 3- which gives me output something like below rel/prod/amp.cfg rel/fld/amp.cfg deb/detail/amp.cfg deb/err/amp.cfg I want to remove trailing "/amp.cfg" so that i should get output something like... (7 Replies)
Discussion started by: anand.shah
7 Replies

4. Shell Programming and Scripting

To remove decimal values from the field

Hi Friends, Hi Friends, I have a file in the following format file.txt 1|jHDJ|1345.0000000|384837843|39084938 2|jkaehjk|5784.00000|jhejhwej|3398934 i want to remove the 3rd field data decimal points from all lines output.txt 1|jHDJ|1345|384837843|39084938... (5 Replies)
Discussion started by: i150371485
5 Replies

5. Shell Programming and Scripting

how to remove a variable starting with dot using sed command

Hi, I want to remove a variable starting with dot(.) in a file using sed command. aaa sss .abc s/^\.abc/d I tried this but it didnt worked. (5 Replies)
Discussion started by: vdhingra123
5 Replies

6. Shell Programming and Scripting

sed command to remove the first field from a '|' delimited file

Hi I have a file with fields delimited by |. I need to remove the first field from the file. I tried cut but it just extracts that field. sample.output abc|100|name1 cde|200|name2 efg|300|name3 Output should be sample.output 100|name1 200|name2 300|name3 thanks Var (6 Replies)
Discussion started by: var285
6 Replies

7. Shell Programming and Scripting

sed remove multiple set of lines in one command

is there a way with sed to removed more than one set of lines in one line? so i mean sed ${firstElem},${lastIndex}d web.xml > web1.xml this will delete lines between ${firstElem},${lastIndex} i want in the same line to do somethinkg like this (doesn't work so far) sed... (3 Replies)
Discussion started by: Poki
3 Replies

8. UNIX for Dummies Questions & Answers

sed command to remove characters help!

I am trying to analyse a large file of sequencing data, example of first 10 lines below, @HWUSI-EAS656_0044_FC:7:1:2447:1039#GCAATT/1 GNCTATGGCTTGCCGGGCTCAGGGAAGACAATCATAGCCATGAAAATCATGGAAAAGATCAGAAAAACATTTCAA +HWUSI-EAS656_0044_FC:7:1:2447:1039#GCAATT/1... (1 Reply)
Discussion started by: Adeleh
1 Replies

9. Shell Programming and Scripting

What's the command to remove empty lines with sed?

3 10 20 10 100 100 10000 Output: 3 10 20 10 100 100 10000 ---------- Post updated at 07:59 AM ---------- Previous update was at 07:56 AM ---------- sed '/^$/d' file doesn't work. (8 Replies)
Discussion started by: cola
8 Replies

10. Shell Programming and Scripting

How to Use Sed Command to replace white spaces with comma from between two fields - Mayank

SHELL SCRIPT Hi I have a file in the following format Mayank Sushant Dheeraj Kunal ARUN Samir How can i replace the white space in between and replace them with a comma?? The resultant output should be Mayank,Sushant Dheeraj,Kunal ARUN,Samir i tried using sed -e... (8 Replies)
Discussion started by: mayanksargoch
8 Replies
Login or Register to Ask a Question