Reading a number of files and and searching for text

P

Paul Donaghy

Hi Guys,

I have a number of results files inside a /results folder such as

/results/results1.txt
/results/results2.txt
...
... and so on.

Inside each of these files are messages either
This feature Passed
This feature Failed

What I want to do is read all of these files /results/results* and pick
out the messages that say FAILED and store them in a variable or
whatever so I can print them to screen.

Any you guys any bright "easy" ideas?

Help much appreciated.Thanks.
 
A

Alex Gutteridge

Hi Guys,

I have a number of results files inside a /results folder such as

/results/results1.txt
/results/results2.txt
...
... and so on.

Inside each of these files are messages either
This feature Passed
This feature Failed

What I want to do is read all of these files /results/results* and
pick
out the messages that say FAILED and store them in a variable or
whatever so I can print them to screen.

Any you guys any bright "easy" ideas?

Help much appreciated.Thanks.


If really that's all you want to do then I'd just use grep rather than
Ruby:

grep FAILED results/*.txt

Alex Gutteridge

Department of Biochemistry
University of Cambridge
 
7

7stud --

Paul said:
Hi Guys,

I have a number of results files inside a /results folder such as

/results/results1.txt
/results/results2.txt
...
... and so on.

Inside each of these files are messages either
This feature Passed
This feature Failed

What I want to do is read all of these files /results/results* and pick
out the messages that say FAILED and store them in a variable or
whatever so I can print them to screen.

Any you guys any bright "easy" ideas?

Help much appreciated.Thanks.


Dir.glob('/results/results*.txt') do |fname|
IO.foreach(fname) do |line|
if line.include?("Passed")
puts line
end
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top