From: Ben Giddings Date: 2005-08-17T06:03:11+09:00 Subject: Re: [Newbie Alert] Probably missing something simple here ... help {wimper} On Tuesday 16 August 2005 16:42, B. Angell wrote: > Am trying to read from a file and write to a number of files based on > the first 4 letters of the data line. Therefore, I want to be able to > write the line: A0037775830|lkajsdlkfjsaljf;lsakjfdsa;jf to file A003 > *and* append all of the A003 lines as well. Here is the hack I have > below, however, produces errors and I know I am missing something > simple/easy ..... as follows: > > #!/usr/bin/ruby -w > File.open("meshdata.txt") do |file| > while line = file.gets > a = line > b = a[0,4] > File.open(b,"w") do |afile| > puts a.afile afile.puts a > end > end > end Ben