作ってみた。
aaa.txtの中から文字列をgrep。
grep_word = (ARGV[0]) out_num = (ARGV[1]).to_i match_num = 0 File.open('aaa.txt', 'r').each_with_index do |line, i| #マッチング処理 if line =~ /#{grep_word}/ match_num = i end #マッチング以降を出力 if match_num != 0 if i > match_num if i <= (match_num + out_num) puts line else break end end end end
aaa.txt
0aaaxxxxxxxxxxxxxxx 1bbbxxxxxxxxxxxxxxx 2cccxxxxxxxxxxxxxxx 3dddxxxxxxxxxxxxxxx 4eeexxxxxxxxxxxxxxx 5fffxxxxxxxxxxxxxxx
結果
./grep_after.rb ccc 2 3dddxxxxxxxxxxxxxxx 4eeexxxxxxxxxxxxxxx