Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. require 'yaml'
  2. lines = []
  3. temp = []
  4. tsv_file = File.open(ARGV[0], 'r')
  5. tsv_file.each_line { |line| lines << line }
  6. tsv_file.close
  7. keys = lines[0].split("\t")
  8. keys.map!(&:chomp)
  9. lines.shift
  10. lines.each do |line|
  11. values = line.split("\t")
  12. students = {}
  13. keys.each_index { |index| students[keys[index]] = values[index].chomp }
  14. temp.push(students)
  15. end
  16. if ARGV[1].nil?
  17. puts temp.to_yaml
  18. else
  19. File.open(ARGV[1], 'w') do |file|
  20. file.puts temp.to_yaml
  21. end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement