Ok everyone I am trying to develop a script that reads a multi-page txt file that contains headers. The file is formatted as such:
Some Company Cool Report Page 1
Batch: 2008 Employee Workload 4/21/2008
234234234234234234 Some Guy Working 20000008
245345345355453545 Some Girl Sleeping 59095093
What I want to do is read the txt file and split it up into numerous txt files. I found the scrip below which allows me to split the file into many txt files but is there a way to tell it to split based on a line?
Meaning look at the top line of the file. This would be the start of each txt file. I can get it to work based on line count but this can very. Any ideas?
Here is the code I am working with:
CODE$lines_per_output_file = 55
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;generate a fake input file for this test
$junk = ""
For $i = 1 To 100
$junk = $junk & $i & @CRLF
Next
$file = FileOpen("test.txt", 2)
FileWrite($file, $junk)
FileClose($file)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;read and split file into an array
$array_of_whole_file = StringSplit(FileRead("MYFILE.TXT"), @CRLF, 1)
$filecnt = 1
$linecnt = 1
While 1
;open a numbered output file
FileOpen("test_" & $filecnt & ".txt", 2)
;write x number of lines to that file
For $i = 1 To $lines_per_output_file
FileWriteLine("test_" & $filecnt & ".txt", $array_of_whole_file[$linecnt])
$linecnt = $linecnt + 1
If $array_of_whole_file[0] = $linecnt Then
FileClose("test_" & $filecnt & ".txt")
Exit
EndIf
Next
FileClose("test_" & $filecnt & ".txt")
$filecnt = $filecnt + 1
WEnd