I need help re-formatting a csv file with half-million records.
I created as script that will reformat the original file, but with this number of records, the script is still running after 10 hrs.
Let's say i have this records:
State Jan Feb Mar Apr May Jun
NY Days 31 29 31 30 31 30
NJ Days 30 30 30 30 30 30
I would like to reformat the file into:
NY Days Jan 31
NY Days Feb 29
NY Days Mar 31
NY Days Apr 30
NY Days May 31
NY Days Jun 30
NJ Days Jan 30
NJ Days Feb 30
NJ Days Mar 30
NJ Days Apr 30
NJ Days May 30
NJ Days Jun 30
''''''''''''''''''''here's my script
''there might be some syntax error (i fixed it for this thread), but it worked with smaller file
set fs = CreateObject ("Scripting.FileSystemObject")
strFile= "c:\test.CSV"
Set f = fs.OpenTextFile(strFile, 1, True)
sContents = ""
Do Until f.AtEndOfStream
'old file format
'NY,Days,31,29,31,30,31,30,,,,,,
'NJ,Days,30,30,30,30,30,30,,,,,,
'new file format
'NY,Days,Jan,31
'NY,Days,Feb,29
'NY,Days,Mar,31
'NY,Days,Apr,30
'NY,Days,May,31
'NY,Days,Jun,30
'......
nrec = ""
newline = ""
strLine = split(f.Readline,",")
nrec = strLine(0) & "," & strLine(1) & ","
for n = 2 to ubound(strLine)
if trim(strLine) = "" then '
else
d = n - 5
newline = nrec & monthname(d,true) & "," & strLine
sContents = sContents & newline & vbCrLf
end if
next
'sContents = sContents & newline & vbCrLf
loop
f.close
set f = fs.getfile(strFile)
nfile = fs.GetParentFolderName(f) & fs.GetBaseName(f) & "_REV." & fs.GetExtensionName(f)
Set f = fs.OpenTextFile(nfile, 2, True)
f.write sContents
f.close
wscript.echo("Completed")
'''''''''''''''''''''
With half-million records and Jan - Dec, my reformatted file will potentially have 6 million records.
I am hoping to import the file either to excel or access and format it from there.
I created as script that will reformat the original file, but with this number of records, the script is still running after 10 hrs.
Let's say i have this records:
State Jan Feb Mar Apr May Jun
NY Days 31 29 31 30 31 30
NJ Days 30 30 30 30 30 30
I would like to reformat the file into:
NY Days Jan 31
NY Days Feb 29
NY Days Mar 31
NY Days Apr 30
NY Days May 31
NY Days Jun 30
NJ Days Jan 30
NJ Days Feb 30
NJ Days Mar 30
NJ Days Apr 30
NJ Days May 30
NJ Days Jun 30
''''''''''''''''''''here's my script
''there might be some syntax error (i fixed it for this thread), but it worked with smaller file
set fs = CreateObject ("Scripting.FileSystemObject")
strFile= "c:\test.CSV"
Set f = fs.OpenTextFile(strFile, 1, True)
sContents = ""
Do Until f.AtEndOfStream
'old file format
'NY,Days,31,29,31,30,31,30,,,,,,
'NJ,Days,30,30,30,30,30,30,,,,,,
'new file format
'NY,Days,Jan,31
'NY,Days,Feb,29
'NY,Days,Mar,31
'NY,Days,Apr,30
'NY,Days,May,31
'NY,Days,Jun,30
'......
nrec = ""
newline = ""
strLine = split(f.Readline,",")
nrec = strLine(0) & "," & strLine(1) & ","
for n = 2 to ubound(strLine)
if trim(strLine) = "" then '
else
d = n - 5
newline = nrec & monthname(d,true) & "," & strLine
sContents = sContents & newline & vbCrLf
end if
next
'sContents = sContents & newline & vbCrLf
loop
f.close
set f = fs.getfile(strFile)
nfile = fs.GetParentFolderName(f) & fs.GetBaseName(f) & "_REV." & fs.GetExtensionName(f)
Set f = fs.OpenTextFile(nfile, 2, True)
f.write sContents
f.close
wscript.echo("Completed")
'''''''''''''''''''''
With half-million records and Jan - Dec, my reformatted file will potentially have 6 million records.
I am hoping to import the file either to excel or access and format it from there.