Parse text with ruby

Hello friends,

I have the following txt log file ==>

···

=================================================================================
[DEBUG] 5/24/07 5:35:50 PM : Finished to read one line : r 250 1006 -63
-65 91 -6 -8 319*
[DEBUG] 5/24/07 5:35:50 PM : Successfully opened DB.
[DEBUG] 5/24/07 5:35:50 PM : Going to read one line.
[DEBUG] 5/24/07 5:35:50 PM : Going to close DB.
[DEBUG] 5/24/07 5:35:50 PM : Successfully closed DB.
[DEBUG] 5/24/07 5:35:50 PM : Going to open DB.
[DEBUG] 5/24/07 5:35:50 PM : Finished to read one line : r 250 1015 -52
-72 91 -6 -8 319*
[DEBUG] 5/24/07 5:35:50 PM : Going to read one line.
[INFO] 5/24/07 5:35:50 PM : Call RaceField constructor.
[INFO] 5/24/07 5:35:50 PM : Opponent has no record of today.
[DEBUG] 5/24/07 5:35:50 PM : Finished to read one line : r 250 1019 -61
-83 92 -7 -8 319*
[DEBUG] 5/24/07 5:35:50 PM : Going to read one line.
[DEBUG] 5/24/07 5:35:50 PM : Going to close DB.

I would like to parse this file with ruby, and to produce a new txt file
where i have only ==>

r 250 1006 -63 -65 91 -6 -8 319*
r 250 1015 -52 -72 91 -6 -8 319*
r 250 1019 -61 -83 92 -7 -8 319*

How can i do that?

thank you
i am a ruby newbie

kostas

--
Posted via http://www.ruby-forum.com/.

Use the right tool(s) for the job:

% cut -f 5 -d: x.txt | grep . | cut -c2-
r 250 1006 -63 -65 91 -6 -8 319*
r 250 1015 -52 -72 91 -6 -8 319*
r 250 1019 -61 -83 92 -7 -8 319*

···

On Jun 1, 2007, at 14:56 , kostas wrote:

I would like to parse this file with ruby, and to produce a new txt file
where i have only ==>

r 250 1006 -63 -65 91 -6 -8 319*
r 250 1015 -52 -72 91 -6 -8 319*
r 250 1019 -61 -83 92 -7 -8 319*

Hi,

I have the following txt log file ==>

<snip>

I would like to parse this file with ruby, and to produce a new txt file
where i have only ==>

r 250 1006 -63 -65 91 -6 -8 319*
r 250 1015 -52 -72 91 -6 -8 319*
r 250 1019 -61 -83 92 -7 -8 319*

You could iterate through each line, scanning for a second ':' and grab all the text after that.

-Mitchell;

···

How can i do that?

thank you
i am a ruby newbie

kostas

kostas wrote:
...

=================================================================================
[DEBUG] 5/24/07 5:35:50 PM : Finished to read one line : r 250 1006 -63
-65 91 -6 -8 319*
[DEBUG] 5/24/07 5:35:50 PM : Successfully opened DB.

...
I think that you should tell us some about this log. Eg if '*' character at the end of line appears always in lines what you want analize?
(and don't appear in others).
The second important thing is a process of cerate log - if date and time
format are 'hard coded' or if they use locale?
...

r 250 1019 -61 -83 92 -7 -8 319*

to see this info at the output i use two ':' characters with separate char behind it. It looks for me to the 'hard coded' in app.

Eg code :

logFile = File.new("path to log file")

logFile.each do |line|
   if line =~ /.*:\s.*:\s.*/
     line.sub!(/.*:\s.*:\s/,'')
     puts line
   end
end

Ryan Davis wrote:

I would like to parse this file with ruby, and to produce a new txt file
where i have only ==>

r 250 1006 -63 -65 91 -6 -8 319*
r 250 1015 -52 -72 91 -6 -8 319*
r 250 1019 -61 -83 92 -7 -8 319*

Use the right tool(s) for the job:

% cut -f 5 -d: x.txt | grep . | cut -c2-
r 250 1006 -63 -65 91 -6 -8 319*
r 250 1015 -52 -72 91 -6 -8 319*
r 250 1019 -61 -83 92 -7 -8 319*

Who knows if that's going to work right if other output is mixed in?

$ ruby -ne 'puts $1 if /Finished to read one line : (.*)/' x.txt
r 250 1006 -63 -65 91 -6 -8 319*
r 250 1015 -52 -72 91 -6 -8 319*
r 250 1019 -61 -83 92 -7 -8 319*

···

On Jun 1, 2007, at 14:56 , kostas wrote:

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Presumably the OP.

···

On Jun 1, 2007, at 15:26 , Joel VanderWerf wrote:

Who knows if that's going to work right if other output is mixed in?