Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ファイルの文字列をソートし直しててファイルに出力する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