I'm posting a dataset in csv format to some database.
The dwelling from the csv files are just like this
Part number, Description, Netto cost, Brutto cost, comment
11009, Ball Bearing, "22,09", "38,05", "Note, this short article is equivalent to koyo xxxxxx"
Like me not acquainted with regular expressions, can someone please put assist me to?
Or simply a write perl script for me personally.
If you're able to handle using Vim (here's a quickstart) to edit your CSV files, this command in Vim would provide you with the behavior you would like, presuming inputs are created as a result (
After that you can hit
:wq in order to save your file and exit this program. That regex (
/"(\d+),(\d+)"/) also needs to function as a beginning reason for other programs (or languages) that accept regular expressions.
You shouldn't have for your it may be completed in MySQL alone.
LOAD DATA INFILE 'data.csv' INTO TABLE prices FIELDS TERMINATED BY ',' ENCLOSED BY '"' (partno, desc, @net, @gross, comment) SET net=REPLACE(@net, ',', '.'), gross=REPLACE(@gross, ',', '.'),
So, you need to replace commas only if float amounts have been in a string delimited by double quotes. This is actually the regexp you would like :
Which may only match and .
Here's the way you would get it done within the Ruby programming language. Unsure if the helps:
row = 'abc, "22,09", t' row.gsub(/([0-9]+),([0-9]+)/, '\1.\2') puts row # result is: abc, "22.09", t
The phone call to gsub looks for any number of numbers then a comma then any number of numbers, and replaces the comma having a period.