Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Last active August 26, 2020 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahemoff/4becce228258bb5da38e9621cc2c029e to your computer and use it in GitHub Desktop.
Save mahemoff/4becce228258bb5da38e9621cc2c029e to your computer and use it in GitHub Desktop.
Split mbox file into N parts
# https://stackoverflow.com/questions/28110536/how-to-split-an-mbox-file-into-n-mb-big-chunks-using-the-terminal
BEGIN {
# Customize this
maxSizeMB=100;
fileCount=0;
currentSize=0;
maxSize=maxSizeMB * 1024 * 1024;
}
/^From / {
filename="mail_" sprintf("%03d",fileCount) ".mbox";
if(currentSize>=maxSize){
close(filename);
print "Saved ", filename, "SIZE ", currentSize ;
currentSize=0;
fileCount++;
}
}
# APPEND EVERY LINE
{
currentSize+=length();
print >> filename
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment