>>29
Ruby で作った

text = <<"EOT"
ab一言コメント:12
あいう コメント:
xyz一言コメント:456
EOT

search_word = "一言コメント:"
sw_length = search_word.length # 7文字

text.each_line do | line | # 1行ずつ処理する
line.strip! # trim

# 単語が見つかった時だけ、単語の前後を出力する
if pos_1 = line.index( search_word )
puts "#{ line[ 0 ... pos_1 ] } - #{ line[ pos_1 + sw_length .. -1 ] }"
end
end

出力
ab - 12
xyz - 456