scmuser created the topic: How to process every line in a text file with Ruby
Example 1
[code language=”css”]
# ruby sample code.
# process every line in a text file with ruby (version 1).
file=’GettysburgAddress.txt’
File.readlines(file).each do |line|
puts line
end
[/code]
Example 2
[code language=”css”]
# ruby sample code.
# process every line in a text file with ruby (version 2).
file=’GettysburgAddress.txt’
f = File.open(file, “r”)
f.each_line { |line|
puts line
}
f.close
[/code]
Source –
alvinalexander.com/blog/post/ruby/how-pr…-line-text-file-ruby
Latest posts by Rajesh Kumar (see all)
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024