From: Robert Schaaf Date: 2009-04-21T09:46:45+09:00 Subject: Re: create a text file with data custom positioned? Your example doesn't match either the number of args (5) or their order. Assuming that you want two field name/index pairs, as suggested by your output, I'd use somefile,printf("%-12s%-8d%-12s%-8d0\n", @fromField, @fromIndex, @toField, @toIndex) Fun stuff, Bob Schaaf On Apr 20, 2009, at 2:35 PM, Mmcolli00 Mom wrote: > Do you know how to create a text file with data custom positioned? > Thanks MC > > Each column starts on a different position > column1 position(0) > column2 position(13) > column3 position(20) > column4 position(28) > > This is an example of the way the text file should look: > > SL_ewer00 45 SL_PRO1 4534 0 > SL_erer 46 SL_PRO2344 46 0 > SL_2344 47 SL_PRO334 47 0 > > #*********SNIPPPET > > doc.elements.each("*//FieldMap") do |element| > @fromField = element.attributes["FromFieldID"] > @toField = element.attributes["ToFieldID"] > @fromIndex = element.attributes["FromIndex"] > @toIndex = element.attributes["ToIndex"] > > File.open('C:\dRar\spn.txt', 'r+') do |f1| > f1.position 0 > f1.puts @fromField > f1.seek 13 > f1.puts "@toField > f1.seek 20 > f1.puts @fromIndex > f1.seek 27 > f1.puts @fromIndex > end > end > -- > Posted via http://www.ruby-forum.com/. >