Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Reading a number of files and and searching for text

Reply
Thread Tools

Reading a number of files and and searching for text

 
 
Paul Donaghy
Guest
Posts: n/a
 
      04-25-2008
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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Alex Gutteridge
Guest
Posts: n/a
 
      04-25-2008
On 25 Apr 2008, at 10:28, Paul Donaghy wrote:
> 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.
> --
> Posted via http://www.ruby-forum.com/.



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





 
Reply With Quote
 
 
 
 
7stud --
Guest
Posts: n/a
 
      04-26-2008
Paul Donaghy wrote:
> 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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Google search result to be URL-limited when searching site, but notwhen searching Web stumblng.tumblr Javascript 1 02-04-2008 09:01 AM
OT: Number Nine, Number Nine, Number Nine FrisbeeŽ MCSE 37 09-26-2005 04:06 PM
Reading a large number of text files into an array Matthew Crema C Programming 4 04-27-2005 09:02 PM
Searching text in Excel, Word files Rene Aguirre Python 0 03-03-2004 04:24 PM
Searching text files hivie C++ 3 07-08-2003 03:42 PM



Advertisments