Merge pull request #14 from github/transpose-encoding
Specify file encoding when transposing CSVs
This commit is contained in:
Коммит
36f2847f31
|
@ -28,7 +28,7 @@ fi
|
|||
_outputfile="${_inputfile%%.*}-transposed.csv"
|
||||
# _outputfile="${_inputfile%%.*}-`date +%Y-%m-%d`.csv"
|
||||
|
||||
cat "${_inputfile}" | "${_transpose}" > "${_outputfile}"
|
||||
"${_transpose}" "${_inputfile}"
|
||||
|
||||
echo "SUCCESS: '${_outputfile}' created"
|
||||
exit 0
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'CSV'
|
||||
|
||||
# Via https://stackoverflow.com/questions/29521170/ruby-transpose-csv
|
||||
rows = CSV.new($stdin).read
|
||||
puts rows.transpose.map { |x| x.join ',' }
|
||||
def get_dest(src)
|
||||
dest = src.split('.')
|
||||
dest[0] += '-transposed'
|
||||
dest.join('.')
|
||||
end
|
||||
|
||||
src = ARGV[0]
|
||||
file = File.open(src, "r:ISO-8859-1")
|
||||
rows = CSV.parse(file)
|
||||
|
||||
CSV.open(get_dest(src), "wb") do |csv|
|
||||
rows.transpose.each do |row|
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче