If I understand you well the script should look like this:
outfile = ARGV.shift
lines = ARGF.readlines
nyomtatvanyazonosito, nev, adoszam, adoazonosito, tol, ig =
lines.slice!(0,6).map {|w| w.chomp.chomp(';') }
first_six_data = <<-EOT
'<?xml version="1.0" encoding="windows-1250"?>'
'<nyomtatvanyinformacio>'
'<nyomtatvanyazonosito>'#{nyomtatvanyazonosito}'</nyomtatvanyazonosito>'
'<adozo>'
'<nev>'#{nev}'</nev>'
'<adoszam>'#{adoszam}'</adoszam>'
'<adoazonosito>'#{adoazonosito}'</adoazonosito>'
'</adozo>'
'<idoszak>'
'<tol>'#{tol}'</tol>'
'<ig>'#{ig}'</ig>'
'</idoszak>'
'</nyomtatvanyinformacio>'
'<mezok>'
EOT
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
But if i run it so in the ouput only the things after the first six
lines appear....
Daniel
···
-----Original Message-----
From: Carlos [mailto:angus@quovadis.com.ar]
Sent: Thursday, March 16, 2006 10:46 AM
To: ruby-talk ML
Subject: Re: add to words syntaxes
Dani wrote:
Thanks, for the answers, but didnt worked. I try to clear my problem,
Here is the input:0608A;
Teszt Kft;
33445566222;
;
20060101;
20060131;
0A0001C002A 33445566222
0A0001C007A Teszt kft
# this text repeat himself with other data several timesThis, should look like this:
<?xml version="1.0" encoding="windows-1250"?>
<nyomtatvanyok>
<nyomtatvany>
<nyomtatvanyinformacio>
<nyomtatvanyazonosito>0608A</nyomtatvanyazonosito>
<adozo>
<nev>Teszt kft</nev> # the first line from the txt
<adoszam>33445566222</adoszam> # second line
<adoazonosito></adoazonosito> #thrid line, in this txt is
blank
</adozo>
<idoszak>
<tol>20060101</tol> # fourth
<ig>20060131</ig> # fifth
</idoszak>
</nyomtatvanyinformacio>
<mezok>
<mezo eazon="0A0001C002A">11111111122</mezo> # and the lines...
<mezo eazon="0A0001C007A">Próba Cég</mezo>
.....
</mezok></nyomtatvany></nyomtatvanyok>So my problem is how can I get an XML source like above. For the
columns
I already have this script:
outfile = ARGV.shiftlines = ARGF.readlines
Well, before you start to loop to fill the "mezo" tags, extract the
other lines:
nyomtatvanyazonosito, nev, adoszam, adoazonosito, tol, ig =
lines.slice!(0,6).map {|w| w.chomp.chomp(';') }
first_six_data = <<-EOT
<?xml ...
<nyomtatvanyinformacio>
<nyomtatvanyazonosito>#{nyomtatvanyazonosito}</nyomtatvanyazonosito>
<adozo>
<nev>#{nev}</nev>
...
EOT
...And then continue processing the array as before.
marked_up_lines = lines.map do |line|
words = line.split
'<mezo eazon="' + words[0] + '">' + words[1] + '</mezo>' + "\n"
endFile.open(outfile,'w') do |file|
file.write first_six_data
file.write marked_up_lines.join
end
HTH
(warning: code not tested)