Skip to content

Instantly share code, notes, and snippets.

@phosphene
Created February 11, 2012 21:17
Show Gist options
  • Save phosphene/1804275 to your computer and use it in GitHub Desktop.
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
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