Skip to content

Instantly share code, notes, and snippets.

@shtaxxx
Created October 24, 2013 08:39
Show Gist options
  • Save shtaxxx/7133418 to your computer and use it in GitHub Desktop.
Save shtaxxx/7133418 to your computer and use it in GitHub Desktop.
Encoding converter
#!/usr/bin/env ruby
IO.popen("nkf -g *","r+"){|io|
while (l = io.gets) != nil
if /(^.*):Shift_JIS$/ =~ l then
tmp = $1
if /(.*)\.Shift_JIS$/ =~ $1 then
next
end
print "S: #{tmp}\n"
system ("cp #{tmp} #{tmp}.Shift_JIS")
system ("nkf -e --overwrite #{tmp}")
elsif /(^.*):ISO-2022-JP$/ =~ l then
tmp = $1
if /(.*)\.ISO-2022-JP$/ =~ $1 then
next
end
print "I: #{tmp}\n"
system ("cp #{tmp} #{tmp}.ISO-2022-JP")
system ("nkf -e --overwrite #{tmp}")
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment