Skip to content

Instantly share code, notes, and snippets.

@rondinif
Created March 30, 2014 17:59
Show Gist options
  • Save rondinif/9876953 to your computer and use it in GitHub Desktop.
Save rondinif/9876953 to your computer and use it in GitHub Desktop.
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