Use each method to loop through a text file
#!/usr/bin/env ruby file = File.open( "myFile.txt" ) file.each { |line| print "#{file.lineno}. ", line } file.close