#!/usr/local/bin/ruby
flie="msg1.txt"
if !test(?r, flie)
  STDERR.printf("%s にメッセージを入れといてね\n", flie)
  exit(1)
end

STDERR.print "戦士よ、汝の名は?: "
name=gets.chomp

open(flie, "r") do |m|
  while msg=m.gets
    print msg.gsub(/%NAME%/){name}
  end
end