#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2003
    Posts
    13
    Rep Power
    0

    Parsing multiple Text Files


    I would like to parse out only the lines that have "FTG in them. Examples:

    "579-617","FTG",0,190,0,190
    "627-580","FTG",843,0,0,843

    The two lines above should be placed into a new file, where I get the chance to save that file were ever I want.

    I also need the last two numbers deleted and the FTG deleted, and all the double quotes.

    I hope this is possible, and if it is, I sure hope someone helps me out.

    Thanks in advance,

    GJ
  2. #2
  3. Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    633
    Rep Power
    15
    What language? VBScript? If so:

    Use The FileSystemObject to open and read the file and create a new file.

    Use Instr() to determine if FTG exists in the line.

    Use Mid(), Left() and Right() to extract the code you want as you step through each line.

    Use Replace() to remove the double quotes.

    You could even split the individual items (delimited by commas) in the line, using the split function, into an array.

    This is not hard, but can be tedious. These functions are at:

    http://msdn.microsoft.com/library/de...ifunctions.asp
    Last edited by dcarva; September 24th, 2003 at 02:04 PM.
  4. #3
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2003
    Posts
    13
    Rep Power
    0
    Yes, very tedious. As for your advice, thank you, I have pretty much decided that I would have to use Instr(), and the Left & Right(). I also thought about the Replace() but was sure how. I just can't figure out how to do this. I have a script allready that at least pulls out the FTG lines and puts it into a new file. But, it doesn't give you the saveas option nor does it parse out everything I mentioned above. Here is that script:



    Dim fs, ts1, sf, s1, ts2, ProjectDir, WshShell, filename, FinalMsg, ErrorMessage, FirstPrompt
    Dim strFilter, strInputFileName, Mystring

    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    FirstPrompt = "Enter Project Directory:"
    ErrorMessage = "GoodBye"
    FinalMsg = "Map Totals operation complete!"

    ProjectDir = InputBox(FirstPrompt,"Map Totals")


    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set fs = CreateObject("Scripting.FileSystemObject")
    'Set ofileSys=CreateObject("Scripting.FileSystemObject" )

    If ProjectDir = "" Then
    Dummy = WshShell.Popup (ErrorMessage,0,"Map Totals",16)
    'Wscript.Quit
    Else

    WshShell.Run "Cmd.exe /C Copy C:\Cablview\" & ProjectDir & "\Dgn\*.txt C:\Cablview\" & ProjectDir & "\Temp\Totals.txt", 2,True
    Set ts1 = fs.OpenTextFile("C:\Cablview\" + ProjectDir + "\Temp\Totals.txt", ForReading)
    Set ts2 = fs.OpenTextFile("C:\Cablview\" + ProjectDir + "\Temp\Miles.txt", ForWriting, True)
    ReadTotals


    Sub ReadTotals()
    Do While Not ts1.AtEndOfStream
    s1 = ts1.ReadLine()
    If InStr(s1, "FTG") > 0 Then
    'here is were the loop goes
    ts2.WriteLine s1
    End If
    Loop
    End Sub





    ts2.Close
    ts1.Close
    Set ts2 = Nothing
    Set ts1 = Nothing
    Set fs = Nothing

    End If
  6. #4
  7. Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    633
    Rep Power
    15
    I think that you have to use CreateTextFile to do a Save As. If not, ts.close will save whatever you wrote to it.

    "nor does it parse out everything I mentioned above"

    What is getting parsed out and what isn't?
  8. #5
  9. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2003
    Posts
    13
    Rep Power
    0
    579-617","FTG",0,190,0,190
    "627-580","FTG",843,0,0,843

    I need the last two numbers, and their commas parsed out. Also, the FTG column needs to be parsed out, and the all of the double quotes need to be parsed out.

    Also, I don't know exactly where in my code that CreateTextFile would be inserted. Sorry for being so ignorant, I'm learning as I go.

    Thanks,

    GJ
  10. #6
  11. Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    633
    Rep Power
    15
    No problem. To make it easy, you could take each item separated by a comma and have it inserted into an array using Split(). This way, you can reference each item in the array and you don't have to worry about parsing each item out using Mid() or Instr().

    http://msdn.microsoft.com/library/de...vsfctsplit.asp

    Here's a way to replace the quotes:

    Dim strVal
    strVal = Replace(strVal, chr(34), "")

    Hope this helps.
  12. #7
  13. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2003
    Posts
    13
    Rep Power
    0
    OK, I have discovered that chr(34) stands for the double quote. I have inserted this line in several places and the script runs, with no errors, yet the double quotes still exist. Also, Not sure how to use Split in my file, considering, lets say in the two row example above, that the 579-617 doesn't always stay three numbers on each side of the dash - it could be 2 numbers on either side, also, the number after the FTG column could be a 2 or three digit number.

    Thanks,

    GJ
  14. #8
  15. Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    633
    Rep Power
    15
    1. Replace
    --------------

    dim x
    x = "test" & chr(34) & "hello"
    reponse.write(x & "<br>")
    x = replace(x, chr(34), "x")
    reponse.write(x & "<br>")

    You should see:

    test"hello
    testxhello

    2. Split
    ---------

    Say that s1 contains "579-617","FTG",0,190,0,190"

    Dim MyString, MyArray
    s1 = Replace(s1, chr(34), "")
    MyArray = Split(s1, ",", -1, 1)
    Response.write ( MyArray(0) & "<br>" )
    Response.write ( MyArray(1) & "<br>" )
    Response.write ( MyArray(2) & "<br>" )
    Response.write ( MyArray(3) & "<br>" )
    Response.write ( MyArray(4) & "<br>" )
    Response.write ( MyArray(5) & "<br>" )

    You will see:

    579-617
    FTG
    0
    190
    0
    190
  16. #9
  17. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Dec 2003
    Posts
    1
    Rep Power
    0
    Originally posted by dcarva


    MyArray = Split(s1, ",", -1, 1)
    Response.write ( MyArray(0) & "<br>" )
    Response.write ( MyArray(1) & "<br>" )
    Response.write ( MyArray(2) & "<br>" )
    Response.write ( MyArray(3) & "<br>" )
    Response.write ( MyArray(4) & "<br>" )
    Response.write ( MyArray(5) & "<br>" )

    You will see:

    579-617
    FTG
    0
    190
    0
    190
    Don't know if this problem has been solved or not, but why not just use a For...Loop to step through the items in the array. If you use this method, it will cut down on the amount of coding you have to do:

    MyArray = Split(s1, ",")

    For i = 0 to UBound(MyArray)
    response.write MyArray(i) & "<br>"
    Next

    This will give you the same result as above.....
    Last edited by AirRazr; December 9th, 2003 at 03:10 PM.

Similar Threads

  1. ASPX files are treated as text files. Why?
    By Steve Schofield in forum .NET Development
    Replies: 3
    Last Post: September 28th, 2004, 07:22 AM
  2. Parsing and rewriting text files
    By brad25 in forum ASP Development
    Replies: 1
    Last Post: November 10th, 2003, 08:48 PM
  3. Reading from 2 text files
    By ns491 in forum ASP Free Lounge
    Replies: 3
    Last Post: October 24th, 2003, 12:07 PM
  4. ASP and text files
    By Steve Schofield in forum ASP Development
    Replies: 1
    Last Post: December 6th, 2000, 03:36 AM
  5. displaying text files without using include file
    By Steve Schofield in forum SQL Development
    Replies: 1
    Last Post: September 19th, 2000, 06:22 AM

IMN logo majestic logo threadwatch logo seochat tools logo