HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 24th, 2003, 11:11 AM
jacksonbilly jacksonbilly is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 13 jacksonbilly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #2  
Old September 24th, 2003, 02:02 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
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/d...rifunctions.asp

Last edited by dcarva : September 24th, 2003 at 02:04 PM.

Reply With Quote
  #3  
Old September 24th, 2003, 02:06 PM
jacksonbilly jacksonbilly is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 13 jacksonbilly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #4  
Old September 24th, 2003, 02:20 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
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?

Reply With Quote
  #5  
Old September 24th, 2003, 02:45 PM
jacksonbilly jacksonbilly is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 13 jacksonbilly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #6  
Old September 24th, 2003, 02:54 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
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/d.../vsfctsplit.asp

Here's a way to replace the quotes:

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

Hope this helps.

Reply With Quote
  #7  
Old September 24th, 2003, 04:12 PM
jacksonbilly jacksonbilly is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 13 jacksonbilly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #8  
Old September 24th, 2003, 04:33 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
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

Reply With Quote
  #9  
Old December 9th, 2003, 03:06 PM
AirRazr AirRazr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 AirRazr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Parsing multiple Text Files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway