// // Legato Code Examples // -------------------- // // Convert EDGAR Company IDX to CSV // // Group: Data // Title: Convert EDGAR Company IDX to CSV // Description: A script demonstrates CSV functions and the FormattedTextToArray function. // Revised: 12/16/2014 // // This script demonstrates CSV functions and the FormattedTextToArray function. // EDGAR IDX files are located in the EDGAR Archive at ftp://edgar.sec.gov. // // This script requires version 0.9f or later of the Legato. // // (c) Novaworks, LLC // string fnSRC, fnDST; string fields[20]; string s1; handle hFile, hOut; int pos[20]; int rc, ix, lx, size, f_size; // -- Set Up Files fnSRC = BrowseOpenFile("Select EDGAR IDX File to Make CSV"); hFile = OpenMappedTextFile(fnSRC); if (IsError(hFile)) { rc = GetLastError(); ReportFileError("Source File", rc); exit; } fnDST = ClipFileExtension(fnSRC); fnDST += ".csv"; hOut = CreateFile(fnDST); if (IsError(hOut)) { rc = GetLastError(); ReportFileError("CSV Output File", rc); exit; } // -- Perform Conversion pos[0] = 62; // Company Name pos[1] = 74; // Form Type pos[2] = 86; // CIK pos[3] = 98; // Date Filed pos[4] = 0; // File Name ProgressOpen("Convert to CSV"); lx = 10; // Data Start size = GetLineCount(hFile); while (lx < size) { ProgressUpdate(lx, size); s1 = ReadLine(hFile, lx); fields = FormattedTextToArray(s1, pos); s1 = CSVArrayToString(fields); WriteLine(hOut, s1); lx++; }