Forum: Ruby Ruby scripting

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Brad W. (Guest)
on 2009-02-26 21:35
Ruby scripting - I am just starting to learn Ruby and I wanted to know
if anyone out there knows it well. I am trying to do a project and I
have run into a problem.

I have an executable file that when run creates (n) number of error
logs. So from a command prompt you run the ,exe with with (n) being the
number of logs you wish to create. We will make n =10. Then using ruby
create a program that will search through those 10 error logs and find
and display how many times the word error is found and how many times
the word warning is found. Then Produce a report showing the number of
error and warning log messages for 10-minute  over the entire length of
time represented by the generated log files.
pat eyler (Guest)
on 2009-02-26 21:41
(Received via mailing list)
On Thu, Feb 26, 2009 at 12:34 PM, Brad W.
<removed_email_address@domain.invalid> wrote:
> error and warning log messages for 10-minute  over the entire length of
> time represented by the generated log files.


sounds rather like a homework assignment ....

what have you tried so far?
Brian C. (Guest)
on 2009-02-26 21:44
Brad W. wrote:
> Ruby scripting - I am just starting to learn Ruby and I wanted to know
> if anyone out there knows it well. I am trying to do a project and I
> have run into a problem.
>
> I have an executable file that when run creates (n) number of error
> logs. So from a command prompt you run the ,exe with with (n) being the
> number of logs you wish to create. We will make n =10. Then using ruby
> create a program that will search through those 10 error logs and find
> and display how many times the word error is found and how many times
> the word warning is found. Then Produce a report showing the number of
> error and warning log messages for 10-minute  over the entire length of
> time represented by the generated log files.

Start by reading a good Ruby primer -
http://www.ruby-doc.org/docs/ProgrammingRuby/ is browsable online for
free, or there are many to choose from any buy. Type in and run the
examples. Then start writing your own code, and when you get stuck at a
particular point, you will be able to ask a more specific question.

For example: if you get stuck at iterating over all the files in a
directory, look at Dir.glob, which is also callable as Dir[]

    Dir["foo.*"].each do |fn|
      puts fn
    end

Also, browse the archives of this list. An almost identical question to
yours (about counting flight arrivals and departures) was asked a day or
two ago.

Good luck,

Brian.
Antonio C. (Guest)
on 2009-02-26 22:01
(Received via mailing list)
On Thu, Feb 26, 2009 at 2:34 PM, Brad W.
<removed_email_address@domain.invalid> wrote:
> I am just starting to learn Ruby and I wanted to know
> if anyone out there knows it well.

Well, there is this one guy in Japan...
Brad W. (Guest)
on 2009-02-26 22:06
Attachment: count.rb (0 Bytes)
pat eyler wrote:
> On Thu, Feb 26, 2009 at 12:34 PM, Brad W.
> <removed_email_address@domain.invalid> wrote:
>> error and warning log messages for 10-minute �over the entire length of
>> time represented by the generated log files.
>
>
> sounds rather like a homework assignment ....
>
> what have you tried so far?

You are fairly close I am studying ruby and have never programed before
this is a test I found and wanted to try. I have attached what I have
and think it should work but I keep getting the following error

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Brad>cd c:\ruby

C:\Ruby>ruby count.rb
count.rb:8:in `initialize': No such file or directory - D:\My
Documents\My Downl
oads\Tezt\files (Errno::ENOENT)
        from count.rb:8:in `new'
        from count.rb:8

C:\Ruby>

I have also used the same script with the error file name
log_file_20090221_095030.txt. I am just using one at this time.
This topic is locked and can not be replied to.