Skip to content

Instantly share code, notes, and snippets.

@shifumin
Created September 2, 2015 07:00
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 shifumin/a003e33101c7537ef456 to your computer and use it in GitHub Desktop.
Save shifumin/a003e33101c7537ef456 to your computer and use it in GitHub Desktop.
ファイルの文字列をソートし直しててファイルに出力するRubyスクリプト
# -*- coding: utf-8 -*-
input_file = ARGV[0]
added_filename = '_in_line'
# 入力ファイルネームが'hoge.txt'なら出力ファイルネームは'hoge_in_line.txt'とする
output_file = File.basename(input_file, '.*') + added_filename + File.extname(input_file)
File.open input_file do |i_file|
File.open output_file, 'w' do |o_file|
o_file.puts i_file.read.split(/\s+/).sort
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment