Find / Replace with grep and Textwrangler

I use grep in TextWrangler to find strings of this type:

 4,600.00 

My regex command is as follows:

 \d.\d{3}.\d{2} 

which seems to find the strings correctly. I would like to replace the line 4,600.00 with 4600.00 , since I want to save the data in a .csv file. How to remove a comma from every number I find?

+7
source share
3 answers

Search: (\d{1,3}),(\d{1,3})\.(\d{1,2})

Replace: \1\2.\3

Powered by TextWrangler.

+12
source

awk oneliner:

 awk --re-interval '{x=gensub(/([0-9]{1,3}),([0-9]{3}\.[0-9]{2})/,"\\1\\2","g");print x}' file 

Test:

 kent$ awk --version|head -1 GNU Awk 3.1.6 kent$ echo "foo,bar,blah,46,000.00,some,more"|awk --re-interval '{x=gensub(/([0-9]{1,3}),([0-9]{3}\.[0-9]{2})/,"\\1\\2","g");print x}' foo,bar,blah,46000.00,some,more 
+1
source

One way: sed :

 sed -r 's/([0-9]{1,3}),([0-9]{3}\.[0-9]{2})/\1\2/g' file.txt 

You can add the -i flag to write changes directly to the file.

0
source

All Articles