Created
          March 27, 2018 13:22 
        
      - 
      
- 
        Save dharshan/7e819801472d373899a7901492cf2c19 to your computer and use it in GitHub Desktop. 
    Innova solutions count host number from file and write to other file
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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