From: Alan Claughan Date: 2009-04-23T02:55:46+09:00 Subject: Re: create a text file with data custom positioned? @col1 = 'SL_ewer00' @col2 = 45 @col3 = 'SL_PRO1' @col4 = 4534 @col5 = 0 outfile = File.open('spn.txt', 'w') outfile.puts "%12s" % @col1 + "%12d" % @col2 + "%12s" % @col3 + "%12d" % @col4 + "%12d" % @col5 outfile.close =begin produces SL_ewer00 45 SL_PRO1 4534 0 =end On 20 Apr 2009, at 8: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/. > > > __________________________________________________ > D O T E A S Y - "Join the web hosting revolution!" > http://www.doteasy.com