word split with 2 columns

D

Dani

Hi everyone!
I need a little help. I have a script for ruby:

outfile =3D ARGV.shift

lines =3D ARGF.readlines
marked_up_lines =3D lines.map do |line|
words =3D line.split
'<mezo eazon=3D"' + words[0] + '">' + words[1] + '</mezo>' + "\n"
end

File.open(outfile,'w') do |file|
file.write marked_up_lines.join
end


This script should split two words with special parameter (from a plain
text it makes xml source). That works so fine if I have ONLY two
columns, but if I put several lines in the txt file beginning it dies.
So, my only question is: how can I bring ruby that it should from line
nr. X (i.e. 6 or 7) begin? And another question: can ruby after the
conversion put in the file a line (ie. </end>)?
Thanks, regards:


Daniel
(e-mail address removed)
 
C

ChrisH

Dani said:
Hi everyone!
I need a little help. I have a script for ruby:

outfile = ARGV.shift

lines = ARGF.readlines
marked_up_lines = lines.map do |line|
words = line.split
'<mezo eazon="' + words[0] + '">' + words[1] + '</mezo>' + "\n"
end

File.open(outfile,'w') do |file|
file.write marked_up_lines.join
end


This script should split two words with special parameter (from a plain
text it makes xml source). That works so fine if I have ONLY two
columns, but if I put several lines in the txt file beginning it dies.
So, my only question is: how can I bring ruby that it should from line
nr. X (i.e. 6 or 7) begin?
....
start_line = 6 #or 7, or whatever...
marked_up_lines = lines[start_line..-1].map do |line|
....
And another question: can ruby after the
conversion put in the file a line (ie. </end>)?
File.open(outfile,'w') do |file|
file.write marked_up_lines.join
file.write '</end>'
end

cheers
 

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
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top