Last active
December 21, 2015 00:08
-
-
Save cieux1/6217309 to your computer and use it in GitHub Desktop.
Shift_JISファイル内を検索するとき用
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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