Skip to content

Instantly share code, notes, and snippets.

@igaiga
Created May 29, 2012 11:53
Show Gist options
  • Save igaiga/2828034 to your computer and use it in GitHub Desktop.
Save igaiga/2828034 to your computer and use it in GitHub Desktop.
# ファイル読み込み
included = [] # 出力用データを格納するArray
in_filename = 'in.txt'
File.open(in_filename, 'r:UTF-8') do |in_file|
while text = in_file.gets
included << text if text =~ /a/
end
end
# ファイルへ書き込み
out_filename = 'out.txt'
File.open(out_filename, 'w:UTF-8') do |out_file|
included.each do |i|
out_file.puts i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment