Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find/Replace using grep and Textwrangler

Tags:

regex

grep

I'm using grep on TextWrangler to find strings of this type:

4,600.00

My regex command is the following:

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

which seems to find the strings correctly. I would like to replace the string 4,600.00 with 4600.00 as I wish to save the data in a .csv file. How do I remove the comma from each number that I find?

like image 989
djq Avatar asked Aug 09 '12 09:08

djq


2 Answers

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

Replace: \1\2.\3

Works in TextWrangler.

like image 102
ZZ-bb Avatar answered Nov 16 '22 16:11

ZZ-bb


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
like image 1
Kent Avatar answered Nov 16 '22 15:11

Kent