Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some CVS transformation in Ruby
> 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
You can’t perform that action at this time.