$ ruby remove_space_from_ruby.rb hoge.txt
などとすると hoge.txt.removed.txt が生成される。
| #!/usr/bin/env ruby | |
| #coding:utf-8 | |
| class String | |
| def remove_space_from_ruby | |
| str = self.dup | |
| self.scan(/<rt>.*?<\/rt>/).each{|x| | |
| str.sub!(/#{x}/ , x.gsub(/ | /, '')) | |
| } | |
| str | |
| end | |
| end | |
| ARGV.each{|x| open("#{x}.removed.txt", 'w'){|f| f.puts open(x).read.remove_space_from_ruby} } |