HELP: Joining 5 large text files

From: Stuart (stuayre_at_hotmail.com)
Date: 08/19/04


Date: 19 Aug 2004 03:05:52 -0700

Hi,

Please can anyone help me join 5 large (1.8gb) text files togeather
to create 1 very large file.

I have some code in PHP but it bombs out at 2gb (seems there is a limit
and php needs re compiling, something thats not an option for me)

I don't want to take up all the servers resources so something that uses
little memory would be very good indeed!

here's the php code if it help...

<?php
set_time_limit(14400000);

$file[0] = "file1.txt";
$file[1] = "file2.txt";
$file[2] = "file3.txt";
$file[3] = "file4.txt";
$file[4] = "file5.txt";

$target = "output.txt";
$handle = fopen($target, 'a');

foreach ($file as $var) {
  $c_handle = fopen($var, 'r');
  do {
       $content = fread($c_handle,1000000);
       fwrite($handle, $content);
  } while (!empty($content));
  fclose($c_handle);
}
?>

all the best

Stu



Relevant Pages

  • Help: joining 5 LARGE text files
    ... Please can anyone help me join 5 large text files togeather ... I have some code in PHP but it bombs out at 2gb (seems there is a limit ... Stu ...
    (comp.lang.perl.misc)
  • Loading 2M array crashes program .. but only some of the time
    ... I have a php - postgresql program which bombs with a statement that it has run out of memory. ... I am running php 5.1.6 and postgres 8.3.something. ... My program bombs, saying that it fails to allocate memory, when it is loading an SQL query result into a php array using pg_fetch_all. ...
    (php.general)
  • Re: [PHP] Loading 2M array crashes program .. but only some of the time
    ... I have a php - postgresql program which bombs with a statement that it has ... run out of memory. ... I am running php 5.1.6 and postgres 8.3.something. ...
    (php.general)