From: ChrisH Date: 2006-11-30T02:00:09+09:00 Subject: Re: Splitting a CSV file into 40,000 line chunks Nice Simon But the 'while row = fin.gets' is skipping a row each time around and you don't handle the header. My "fix": Simon Strandgaard wrote:... > File.open("test", "w+") do |f| > 20.times do |i| > f.write "abc|def|ghi#{i}\n" > end > end > > File.open("test", "r") do |fin| > part = 0 header = fin.gets row = fin.gets while row > > File.open("test_part#{part}", "w+") do |f| f.write(header) > 5.times do > f.write(row) > break unless row = fin.gets > end > end > > part += 1 > end > end ... Cheers Chris