From: Robert Hansen Date: 2012-06-04T22:32:30+09:00 Subject: Re: Read from several .txt files by a pattern and write the matched lines to a new file $files = Array.new Dir.glob("**/Msg.log").entries.each { |n| $files.push(n) if File.file?(n) } puts "\n#{$files.size} files found\n" pattern = /(failed)/m $files.each do |element| f = File.open(element, 'r') lines = f.readlines lines.each do |line| if line.match(pattern) File.open('newfile.txt', 'w') do |write| <-- Problem write.puts(line) end end end f.close end My problem is where the "if statement" begins. I am sorry to say that my compiler does not give me any error message, but the "newfile.txt" will not be created and therefore not written to. This makes no sense to me since I am a new beginner at Programming/scripting As for your code, "$ find . -type f -name Msg.log -exec fgrep failed {} + >newfile.txt" looks pretty and neat, but I am afraid it is way over my head. Kind regard, Robert Hansen -- Posted via http://www.ruby-forum.com/.