Skip to content

Instantly share code, notes, and snippets.

@mokies
Last active December 24, 2015 19:09
Show Gist options
  • Save mokies/6847883 to your computer and use it in GitHub Desktop.
Save mokies/6847883 to your computer and use it in GitHub Desktop.
Ruby script for Louise to replace <P00000> place holder text with incrementing identifier eg. <P00001>
#!/usr/bin/env ruby
class Identify
def insertIdentifiers (fileName)
out_filename = fileName.gsub(".rtf", "-transformed.rtf")
puts out_filename
out_file = File.new(out_filename, "w")
count = 0
replace_proc = proc do
count += 1
'<P' + count.to_s.rjust(5, '0') + '>'
end
File.open(fileName).each { |line|
out_file.puts line.gsub(/<P00000>/, &replace_proc)
}
end
end
if __FILE__ == $0
if ARGV.length == 0
abort "\nError: Louise, an input file name is required. Aborting...\n\n"
elsif ARGV.length > 2
abort "\nError: The program takes one arguments maximum. Aborting...\n\n"
end
proc = Identify.new
proc.insertIdentifiers(ARGV[0])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment