Skip to content

Instantly share code, notes, and snippets.

@thinkAmi
Created March 1, 2013 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkAmi/5068282 to your computer and use it in GitHub Desktop.
Save thinkAmi/5068282 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
# RubyでFromTo表現のテキストファイルを、カウントアップ表現に変換する
# 使い方
# convert.rb 変換前のファイルパス > 変換後のファイルパス
export_count = 0;
while line = gets
line.lstrip!
if line =~ /^([a-z]|[A-Z])?[0-9]{1,4}.([a-z]|[A-Z])?[0-9]{1,4}/
results = line.scan(/[0-9]{1,4}/)
first = results[0]
last = results[-1]
first.to_i.step(last.to_i, 1) { |n|
formatted = format("%04d", n)
puts "x" + formatted + "x"
export_count += 1
}
end
end
puts export_count.to_s + "件"
@thinkAmi
Copy link
Author

thinkAmi commented Mar 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment