Skip to content

Instantly share code, notes, and snippets.

@ayumin
Created July 28, 2009 05:19
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 ayumin/156946 to your computer and use it in GitHub Desktop.
Save ayumin/156946 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
KeyWord = case ARGV[0] do
when "--cpu" then /^CPU used by this session/
when "--cpu" then /^CPU used by this session/
when "--cpu" then /^CPU used by this session/
when "--cpu" then /^CPU used by this session/
end
# カレントディレクトリの末尾".txt"で終わる全てのファイルを抽出する
# 抽出したファイルからキーワードにマッチする行のみを出力する
Dir.glob("*.txt").sort.each do |path|
File.open(path,'r') do |file|
file.each_line do |line|
puts line if line =~ KeyWord
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment