Created
March 30, 2014 17:59
-
-
Save rondinif/9876953 to your computer and use it in GitHub Desktop.
Some CVS transformation in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> cat workfile.csv | ruby -rcsv -ne ' | |
row = CSV.parse_line($_) | |
puts CSV.generate_line(row, {col_sep: ";" }) | |
' > work1.csv | |
> cat workfile.csv | ruby -rcsv -ne ' | |
row = CSV.parse_line($_) | |
row.each {|elem| elem.tr!(",.",".,") if elem.match(/^-?[0-9,.]+$/)} | |
puts CSV.generate_line(row, {col_sep: ";" }) | |
' > work2.csv | |
> cat workfile.csv | ruby -rcsv -ne ' | |
row = CSV.parse_line($_) | |
row.each {|elem| | |
elem.tr!(",.",".~") if elem.match(/^-?[0-9,.]+$/) | |
elem.tr!("~","") if elem.match(/~/) | |
} | |
puts CSV.generate_line(row, {col_sep: ";" }) | |
' > work3.csv | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see also http://stackoverflow.com/questions/22742686/change-number-locale-format-in-csv-text-swap-dot-with-comma-in-numbers and https://gist.github.com/ryenus/1518596