Skip to content

Instantly share code, notes, and snippets.

@cieux1
Last active December 21, 2015 00:08
Show Gist options
  • Select an option

  • Save cieux1/6217309 to your computer and use it in GitHub Desktop.

Select an option

Save cieux1/6217309 to your computer and use it in GitHub Desktop.
Shift_JISファイル内を検索するとき用
#! /usr/bin/local/ruby
# -*- encoding: utf-8 -*-
require 'uri'
def find_matched(arr, reg, reg2)
puts "検索文字列1:" + reg
puts "検索文字列2:" + reg2
arr.each do |file_name|
htmlname = File.dirname(file_name) + "/" + File.basename(file_name)
open(file_name, "r:Shift_JIS:UTF-8", :invalid => :replace, :undef => :replace, :replace => '?') do |f|
s = f.read
if /(#{reg})/ =~ s
puts "html: " + htmlname
puts $1, $2
else
#puts htmlname
end
end
end
end
html_array = Dir.glob("DOMAIN_NAME/**/*.{html,htm}")
reg = 'foo'
reg2 = ''
find_matched(html_array, reg, reg2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment