Page 2 of 2 < 1 2
Topic Options
#58084 - 07/06/21 09:31 AM Re: How to split a large data file by States [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 393
Loc: Home
Can anyone help here?
_________________________
Peace

Top
#58087 - 07/06/21 02:07 PM Re: How to split a large data file by States [Re: Sami786]
Philippe F. Offline
OL Expert

Registered: 09/06/00
Posts: 1968
Loc: Objectif Lune, Montreal, Qc
Try this:
var FSO = new ActiveXObject("Scripting.FileSystemObject");

var inputFile = FSO.OpenTextFile(Watch.GetJobFileName(),1);
var outputFiles = {};
var stateProv = "";
var line="";

// Eliminate header line
line = inputFile.ReadLine();

while (!inputFile.AtEndOfStream) {
  line      = inputFile.ReadLine();
  stateProv = line.split(",")[7];
  // Check if property exists, otherwise create it and assign newly created file handle to it
  if(!outputFiles[stateProv]){
    outputFiles[stateProv] = FSO.CreateTextFile("C:\\Tests\\Output\\" + stateProv + ".txt");
  }
  outputFiles[stateProv].WriteLine(line);
}

//Close all files
for(var i in outputFiles) outputFiles[i].Close();

_________________________
Technical Product Manager
I don't want to achieve immortality through my work; I want to achieve immortality through not dying - Woody Allen

Top
#58091 - 07/08/21 09:28 AM Re: How to split a large data file by States [Re: Sami786]
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 393
Loc: Home
Thank you Philippe, I tested your script its working very smart and fast smile Mercy.

Greatly appreciated.
_________________________
Peace

Top
Page 2 of 2 < 1 2