Это версия Ruby
str_list = ['text', 'thing', 'try', 'Better']
File.open(ARGV[0]) do |f|
lines = f.readlines
lines.each_with_index do |l, idx|
if l.match(str_list[idx])
l = l.split(' ')
if l.length == 1
puts l[0]
else
puts l[0] + "\t" + str_list[idx]
end
end
end
end
В образце текстового файла hello.txt содержится
This is a single text line
Another thing
It is better you try again
Better
Запуск с ruby source.rb hello.txt приводит к
This text
Another thing
It try
Better