parse text with ruby

K

kostas

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
 
R

Ryan Davis

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*
 
J

Joel VanderWerf

Ryan said:
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*
 
M

mitchell

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;
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top