Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Innova solutions count host number from file and write to other file
filename = gets.strip
res = []
File.open(filename).each do |line|
res << line.split(' ').first
end
res_hash = Hash.new(0)
res.each { |i| res_hash[i] += 1 }
text_array = res_hash.to_a.map { |res| res.join(' ') }
out_filename = 'records_'+filename
File.open(out_filename, 'w+') do |file|
text_array.each { |elem| file.puts(elem) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment