Skip to content

Instantly share code, notes, and snippets.

@jamesmontalvo3
Created March 3, 2016 01:09

Revisions

  1. jamesmontalvo3 created this gist Mar 3, 2016.
    29 changes: 29 additions & 0 deletions Split.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    fs = require('fs');
    path = require('path');

    var log = path.join( path.dirname( fs.realpathSync(__filename) ), 'meza-dev.log' );

    fs.readFile( log, 'utf8', function(err,data){
    if (err) {
    return console.log(err);
    }

    var lines = data.split("\n");
    var count = lines.length;

    console.log( count + " lines..." );

    var i = 0;
    var newFileText = "";
    while( lines[i] ) {
    newFileText += lines[i] + "\n";
    if ( i % 20000 === 0 ) {
    fs.writeFile( "log" + i + ".log", newFileText.substr(), 'utf8', function(err){
    if(err) { console.log(err); }
    });
    newFileText = "";
    }
    i++;
    }

    });