Basic iteration through text

B

Ben Martinek

Howdy!

So I am trying to parse a bit of an ugly text file to a new file, and
hence read each line of the old file, check the line for some conditions
and then execute some other stuff, and then write out some results to a
new file. Here is what I came up with:

my_file = File.new("New_file.txt", "w+")

File.foreach("LOG02.txt") do |line|
if line =~/^\$GPRMC/.
my_file.puts line
else
print "I did not read this line: #{line}"
end
end

I have a feeling that I am missing something stupid but not quite sure
what it is.

Good karma for a solution :)
 
B

Ben Martinek

Ben said:
Howdy!

So I am trying to parse a bit of an ugly text file to a new file, and
hence read each line of the old file, check the line for some conditions
and then execute some other stuff, and then write out some results to a
new file. Here is what I came up with:

my_file = File.new("New_file.txt", "w+")

File.foreach("LOG02.txt") do |line|
if line =~/^\$GPRMC/.
my_file.puts line
else
print "I did not read this line: #{line}"
end
end

I have a feeling that I am missing something stupid but not quite sure
what it is.

Good karma for a solution :)

Okay solved my problem, it was something stupid, like the period I
didn't see after my line match statement.

Nothing to see here people, move along....
 

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,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top