Created
February 11, 2012 21:17
-
-
Save phosphene/1804275 to your computer and use it in GitHub Desktop.
find and add numbers at first position of lines only in text 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
File.open('test.txt', 'r') do |f| | |
count = 0 | |
f.each_line do |line| | |
if line =~ /^(\d+)/ | |
count = count + $1.to_i | |
end | |
end | |
puts count | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment