SyntaxFix
Write A Post
Hire A Developer
Questions
It is because of the endlines in each lines. Use the chomp method in ruby to delete the endline '\n' or 'r' at the end.
line_num=0 File.open('xxx.txt').each do |line| print "#{line_num += 1} #{line.chomp}" end