Skip to content

Instantly share code, notes, and snippets.

@gfontenot
Created May 24, 2012 21:23
Show Gist options
  • Save gfontenot/2784315 to your computer and use it in GitHub Desktop.
Save gfontenot/2784315 to your computer and use it in GitHub Desktop.
Titlecase lines in a file
  1. Download the script locally (button above)
  2. Copy names into a .txt file called input.txt in the same directory as the script
  3. cd into the dir with terminal
  4. run ruby titlecase_lines.rb
  5. Copy from input.txt back into excel

Hope this works for you.

#!/usr/bin/env ruby
new_lines = []
File.open("input.txt", "r+") do |f|
f.each do |l|
title_name = l.gsub(/\w+/) do |word|
word.capitalize
end
new_lines << title_name
end
f.rewind
new_lines.each do |l|
f.puts l
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment