Split a .mbox file into chunks

Apparently, Apple Mail insists on copying the entire .mbox file contents into RAM when importing...

The MBOX format is essentially a textual format for exporting emails as single files. As a result, if you try to export several years of emails, these files can get big pretty quickly.

While this may not be a problem, some email clients such as Apple Mail insist on doing stupid things like loading (very inefficiently, too) the entire contents of the file into RAM when importing it, which will likely cause your MacBook to scream that you are out of application memory.

To avoid this, you can use this nifty script to tidily split your .mbox file into chunks of 1GB each (adjust as needed):

    /^From /{
    if(filesize>=1000000000){#file size per chunk in byte
        close("chunk_" chunk ".txt");
  {print > ("chunk_" chunk ".txt")}

Credits: StackOverflow