Searching/parsing a .csv file

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 13 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
trulofy
Posts: 12
Last visit: Wed Aug 04, 2010 7:10 am

Searching/parsing a .csv file

Post by trulofy »

I need help im new to scripting and to vb I need to find specific information in my csv files here is the format for the csv files opened in notepad :"OLEAutomationDate(UTC)","Tick" i need to find ticks that are higher than a set value and parse out the lines to a new file any help would be much appreciated.Thanks in advance.
User avatar
trulofy
Posts: 12
Last visit: Wed Aug 04, 2010 7:10 am

Searching/parsing a .csv file

Post by trulofy »

Thanks for the information. im still having issues becuase im trying to read a .csv file using objFSO.OpenTextFile it doesnt find the file specified. Here is a code snippet:Const ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject")Set objTextFile = objFSO.OpenTextFile("C:Users"xxxxxx".Integer.Tick.csv", ForReading)Do While objTextFile.AtEndOfStream <> True If inStr(objtextFile.Readline, ",") Then TickCounts = split(objTextFile.Readline, ",") Wscript.Echo "OLEAutomationDate(UTC): " & TickCounts(0) Wscript.Echo "Tick: " & TickCounts(1) else objTextFile.Skipline End If i = i + 1LoopobjTextFile.CloseThe xxxx in quotes are my path I cannont disclose this information NDA reasons. If anyone can help me with this issue the help would be much appreciated and again Thank You in advance.EDIT: I can open the file if I convert it to a .txt file just so you know.trulofy2010-07-22 14:01:35
User avatar
trulofy
Posts: 12
Last visit: Wed Aug 04, 2010 7:10 am

Searching/parsing a .csv file

Post by trulofy »

what exactly are you referring to beucase the xxxx info has quotes around in the code snippet but not in the actual scriptEDIT: Well I ran the script again and now its working! I didnt change anything so im not sure what was going on there maybe the file that I was testing the script on was being written to at that very moment?!? well anyways thanks for the help again. I'am getting an error when the script is done running though. the error reads:cscript runtime error: Input past end of fileIm sure this isnt a big deal.EDIT#2: so i looked into the file that im opening and at the end of the file there is a few integers which look to be the beginning of the next line but since this file is constantly written to I believe that when the script is ran the last line there is not complete so it misinterprets/cant read the information and gives me the above error.
trulofy2010-07-22 15:24:15
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Searching/parsing a .csv file

Post by jvierra »

You are doing both read and skip but only testing fo reof once. If you skip at eof you will get an error.

YOur quotes around teh xx/xx are in the code you posted. No one could guess that it was not really ther.
Dorothy - are we really in Kansas still. - No dear the quotes don't really exists.

Or - as Zorba would say - Hoopa!
User avatar
trulofy
Posts: 12
Last visit: Wed Aug 04, 2010 7:10 am

Searching/parsing a .csv file

Post by trulofy »

Thanks for the help anyways but if you would have read my entier post I did state the xxxx within quotes were not really there because I cant post the information on a public forum because of NDA purposes.
User avatar
trulofy
Posts: 12
Last visit: Wed Aug 04, 2010 7:10 am

Searching/parsing a .csv file

Post by trulofy »

ok I need some more help ive been doing some research on file handeling/searching and I cant seem to find anything that can help me find a specific file with a folder here is an example of the different file names within the folder and the one that i'am looking for.Ex1 different file names within said folder: xx.xx.xx.xx.xxxxxx.DA00INMON001.ToolServer.xxxx.Integer.Uptime_(minutes).csvxx.xx.xx.xx.xxxxx.DA01GMDST001.DistrictServer.xxxxx.Integer.Client_Send_Bytes.csvxx.xx.xx.xx.xxxxx.DA01GMDST001.DistrictServer.xxxxx.String.District_Name.csvEx2 specific file i'm looking for within said folder:xx.xx.xx.xx.xxxxx.DA01GMDST001.DistrictServer.xxxxx.Integer.Tick.csvThe underlined word in the last file is what im looking for with in the files in this particular folder nothing else within the file name is of importance to me I need to collect the tick files within the DB folder that we save all the information to. Also this is done locally if that helps any?!?. Any help would be a god send im reading VBscript, WMI, and ADSI Unleased By. Don Jones but I really need to get moving on this script I know its simple but I'am having issues finding the right information.NOTE: all of the xx's are ips and ports that I cannot post on a public forum.Thanks in advance.Travis Urban
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Searching/parsing a .csv file

Post by jvierra »

Sorry but I have no idea what you are asking. What code? What does earlier mean?

User avatar
trulofy
Posts: 12
Last visit: Wed Aug 04, 2010 7:10 am

Searching/parsing a .csv file

Post by trulofy »

Const ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject")Set objTextFile = objFSO.OpenTextFile("C:Users"xxxxxx".Integer.Tick.csv", ForReading)Do While objTextFile.AtEndOfStream <> True If inStr(objtextFile.Readline, ",") Then TickCounts = split(objTextFile.Readline, ",") Wscript.Echo "OLEAutomationDate(UTC): " & TickCounts(0) Wscript.Echo "Tick: " & TickCounts(1) else objTextFile.Skipline End If i = i + 1LoopobjTextFile.Closethis is the code that i meant it was earlier in this thread but instead of looking for a specific file i need to read in several files with the word "tick" in thier file name and run the Do While on each file.
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Searching/parsing a .csv file

Post by rasimmer »

Const FOR_READING = 1Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")Dim colFiles : Set colFiles = objFSO.GetFolder("C:Tick_Folder").FilesDim objFileFor Each objFile in colFiles If InStr(UCase(objFile.Name), "TICK") Then Dim objTextStream : Set objTextStream = objFile.OpenAsTextStream(FOR_READING) Do Until objTextStream.AtEndOfStream ' Your code Loop objTextStream.Close End IfNext
This topic is 13 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked