From: Dani Date: 2006-03-16T18:14:15+09:00 Subject: Re: add to words syntaxes 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 times This, should look like this: 0608A Teszt kft # the first line from the txt 33445566222 # second line #thrid line, in this txt is blank 20060101 # fourth 20060131 # fifth 11111111122 # and the lines... Pr�ba C�g ..... So my problem is how can I get an XML source like above. For the columns I already have this script: outfile = ARGV.shift lines = ARGF.readlines marked_up_lines = lines.map do |line| words = line.split '' + words[1] + '' + "\n" end File.open(outfile,'w') do |file| file.write marked_up_lines.join end This works fine, but I dont know what to do with the first 6 lines to bring it to look like above and how can I bring ruby to repeat himself and what for a character need I to use for repeating.. Regards, Daniel -----Original Message----- From: Ross Bamford [mailto:rossrt@roscopeco.co.uk] Sent: Thursday, March 16, 2006 9:42 AM To: ruby-talk ML Subject: Re: add to words syntaxes On Thu, 2006-03-16 at 16:25 +0900, Dani wrote: > Hi! > Still have a question: I have a txt file with words, seperated with > semicolon or linebreaks. looks like this: > Teszt Kft > 33445566222 > ; > 20060101 > 20060131 > 0A0001C002A 33445566222 > 0A0001C007A Teszt kft > > I need that ruby add to each line several XML tags. So lets say: > Teszt Kft > 33445566222 > > and so on... from line 6 (where are two columns) should ruby use > another (ruby)script. And when it reached the end of the section (where > could be an escape character or something, what it changes to ie. > ) begin from front, so long it has no more escape characters. > So, how can I do this? Please if you can help me... Perhaps it's me not being awake properly, but it doesn't seem very clear from your question exactly what you want to do? To clarify: + Are the lines you want to process always in sets of 3 (or whatever number)? Or is it single-line, with some way to choose which tag goes on a given line? + What do you mean 'use another script' for the two-column lines? I note as well that it could be difficult to determine which lines are two column, since spaces seem to be allowed in the processed input anyway. Anyway, I'm sure this isn't what you're after, but maybe it'll point you in the right direction. Failing that, post a bit more detail and sample input/output and I'm sure you'll get what you need. s = "" s.gsub(/^(.*)$/) { "#$1" } # => "Teszt Kft # 33445566222 # ; # 20060101 # 20060131 # 0A0001C002A 33445566222 # 0A0001C007A Teszt kft" s.map { |line| "#{line.chomp}\n" }.join # => as above s.map do |line| tag = (line =~ /^\d+$/) ? 'foo' : 'bar' "<#{tag}>#{line.chomp}\n" end.join # => "Teszt Kft 33445566222 ; 20060101 20060131 0A0001C002A 33445566222 0A0001C007A Teszt kft" -- Ross Bamford - rosco@roscopeco.REMOVE.co.uk