Announcement

Collapse
No announcement yet.

Help wil parse text file with vbscript

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help wil parse text file with vbscript

    I have a text file with 10,000 + lines of data. The data is in the following format.

    20091228 050036;78349;1

    The first 8 are the date.

    I would like to perform the following

    1) read and process all lines in the source text file
    2) Set a variable in the script for the day of the week (ie Monday)
    3) Analyze each line of the source and determine if the date is a Monday
    4) if date is a Monday copy that entire line into another text file
    5) if date is not a Monday go to the next line

    Thanks in advance for the help

  • #2
    Re: Help wil parse text file with vbscript

    This should do the trick. Usage:
    Code:
    cscript.exe TheScript.vbs AllDates.txt OnlyMondays.txt
    Code:
    Code:
    Option Explicit
    
    Dim dotw
    Dim fileData
    Dim fileName
    Dim fso
    Dim line
    Dim outFile
    Dim outputFileName
    Dim sourceFileName
    Dim thisDate
    
    ' Can be vbSunday, vbMonday, vbTuesday, vbWednesday,
    ' vbThursday, vbFriday, vbSaturday
    dotw = vbMonday
    
    sourceFileName = WScript.Arguments(0)
    outputFileName = WScript.Arguments(1)
    
    WScript.Echo "Parsing file: " & sourceFileName & "..."
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    fileData = Split(fso.OpenTextFile(sourceFileName, 1, False).ReadAll, vbCrLf, -1, vbTextCompare)
    
    Set outFile = fso.OpenTextFile(outputFileName, 8, True)
    
    For Each line In fileData
    	If (Len(Trim(line)) >= 8) Then
    		thisDate = CDate(Mid(line, 5, 2) & "/" & Mid(line, 7, 2) & "/" & Mid(line, 1, 4))
    		
    		If Weekday(thisDate) = dotw Then
    			outFile.WriteLine line
    		End If
    	End If
    Next
    
    outFile.Close
    Set outFile = Nothing
    Set fileData = Nothing
    Set fso = Nothing
    
    WScript.Echo "[Done] Output written to: " & outputFileName
    Jay Adams, Noxigen LLC

    Comment


    • #3
      Re: Help wil parse text file with vbscript

      The scripts work great

      Thanks

      Comment


      • #4
        Re: Help wil parse text file with vbscript

        Awesome. Glad I could help!
        Jay Adams, Noxigen LLC

        Comment

        Working...
        X