I am working with a file that has numbers and let开发者_如何学编程ters in it. I managed to remove the letters with regexps, but when I try to output the file with just the numbers in using:
matchIt = File.open('numbers.txt', 'a') {|f| f.write(string[i]) }
they appear attached together like this:
1613714531731413747
When I run a ruby script from the terminal, I normally type:
ruby script.rb > numbers.txt
which would then format the numbers downward:
1
2
3
4
5
Can I do the same thing with ruby using the command I have above?
If you're looking to print a new line for each number, just use f.puts
instead of f.write
.
精彩评论