?
Solved

Parsing multiple files into columns in excel with special character deliminators

Posted on 2010-03-26
6
Medium Priority
?
845 Views
Last Modified: 2013-11-25
I have 13 text files each one with a command line with many switches. I am looking for an external (something I can execute in DOS or mouse clic) VBS snippet (NOT VBA)  that can read in an array (or external list) of files and parse the string using "/" as a deliminator in each file, and list the results in a column in excel.

Example 1: First File

String found in somefile001.txt

"D:\Program Files\PIPC\Interfaces\RDBMSPI\RDBMSPI.exe" 1 /BAD1=1 /BAD2=1 /DEB=0 /DSN=CAMPSPRINGSI /NO_INPUT_ERROR /OUTPUT="D:\Program Files\PIPC\Interfaces\RDBMSPI\Log\RDBMSPI.out" /SQL="D:\Program Files\PIPC\Interfaces\RDBMSPI\SQL" /SUCC1=0 /SUCC2=0 /USER_ODBC=odbc /PS=RDBMS /ID=1 /host=CS1-PI:5450 /pisdk=1 /maxstoptime=120 /pisdktimeout=60 /perf=8 /pisdkConTimeout=15 /UFO_SYNC="\\CS1-PI-INT2\UFO2 Files Share\RDBMSPI_RDBMS_1.dat" /UFO_TYPE=COLD /UFO_ID=1 /UFO_OtherID=2 /f=00:05:00 /f=00:05:00 /f=00:05:00

Desired output in an excel spreadsheet (Column A)
 
/BAD1=1
/BAD2=1
/DEB=0
/DSN=CAMPSPRINGSI
/NO_INPUT_ERROR
/OUTPUT="D:\Program Files\PIPC\Interfaces\RDBMSPI\Log\RDBMSPI.out" /SQL="D:\Program Files\PIPC\Interfaces\RDBMSPI\SQL"
/SUCC1=0
/SUCC2=0
/USER_ODBC=odbc
/PS=RDBMS
/ID=1
/host=CS1-PI:5450
/pisdk=1
/maxstoptime=120
/pisdktimeout=60
/perf=8
/pisdkConTimeout=15
/UFO_SYNC="\\CS1-PI-INT2\UFO2 Files Share\RDBMSPI_RDBMS_1.dat" /UFO_TYPE=COLD
/UFO_ID=1
/UFO_OtherID=2
/f=00:05:00
/f=00:05:00
/f=00:05:00

Example 1: Second File

String found in differentfile2.txt

"D:\Program Files\PIPC\Interfaces\RDBMSPI\RDBMSPI.exe" 1 /BAD1=1 /BAD2=1 /DEB=0 /DSN=CAMPSPRINGSI /NO_INPUT_ERROR /OUTPUT="D:\Program Files\PIPC\Interfaces\RDBMSPI\Log\RDBMSPI.out" /SQL="D:\Program Files\PIPC\Interfaces\RDBMSPI\SQL" /SUCC1=0 /SUCC2=0 /USER_ODBC=odbc /PS=RDBMS /ID=1 /host=CS1-PI:5450 /pisdk=1 /maxstoptime=120 /pisdktimeout=600 /perf=9 /pisdkConTimeout=15 /UFO_SYNC="\\CS1-PI-INT2\UFO2 Files Share\RDBMSPI_RDBMS_1.dat" /UFO_TYPE=COLD /UFO_ID=1 /UFO_OtherID=2 /f=00:05:00 /f=00:05:00 /f=00:05:00

Desired output in an excel spreadsheet (Column B)
 
/BAD1=1
/BAD2=1
/DEB=0
/DSN=CAMPSPRINGSI
/NO_INPUT_ERROR
/OUTPUT="D:\Program Files\PIPC\Interfaces\RDBMSPI\Log\RDBMSPI.out" /SQL="D:\Program Files\PIPC\Interfaces\RDBMSPI\SQL"
/SUCC1=0
/SUCC2=0
/USER_ODBC=odbc
/PS=RDBMS
/ID=1
/host=CS1-PI:5450
/pisdk=1
/maxstoptime=120
/pisdktimeout=600
/perf=9
/pisdkConTimeout=15
/UFO_SYNC="\\CS1-PI-INT2\UFO2 Files Share\RDBMSPI_RDBMS_1.dat" /UFO_TYPE=COLD
/UFO_ID=1
/UFO_OtherID=2
/f=00:05:00
/f=00:05:00
/f=00:05:00

Each delimited ("/) string takes up a cell in excel and continues vertically until the entire string is in list format. Closes file, opens the next file, does the same thing, and prints the parsed string on the next column in excel.
multi-file-parser.jpg
0
Comment
Question by:NanohurtzChrome
  • 3
  • 2
6 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 2000 total points
ID: 28732472
Hi NC,

Do you want to list the files in the code, or do you want to be able to click/drag them into the file?

If you want to hard code them, just copy the attached code snippet into a .vbs file, alter the vFiles list at the top, and run.

If you want to click/drag files into the .vbs file in windows explorer, you'll need to make two changes to the code:

1) Remove or comment out the vFiles = ... line
' vFiles = Array("C:\somefile001.txt", "C:\somefile002.txt")

2) Change the For Each line to the following:
 For Each vFile in WScript.Arguments

The only thing I wasn't fully sure on is the first part of the file contents, before the first argument, which lists the executable. Do you really not want to include this in the excel file? If so, use this NanohurtzSplit function instead:
Function NanohurtzSplit(vFilePath)
 Dim FSO, TS, FileCont, vContents, i, vNewArray
 Set FSO = CreateObject("Scripting.FileSystemObject")
 Set TS = FSO.OpenTextFile(vFilePath, 1)
 FileCont = TS.ReadAll
 TS.Close
 Set TS = Nothing
 Set FSO = Nothing
 vContents = Split(FileCont, "/")
 ReDim vNewArray(UBound(vContents) - 1)
 For i = LBound(vContents) + 1 To UBound(vContents)
  vNewArray(i - 1) = "/" & vContents(i)
 Next
 NanohurtzSplit = vNewArray
End Function

Let me know how it fares!
Matt
Dim vArray, xlApp, i, vFile, vFiles
 vFiles = Array("C:\somefile001.txt", "C:\somefile002.txt")
   
 Set xlApp = CreateObject("excel.application")
 xlApp.Workbooks.Add

 i = 1
 For Each vFile in vFiles
  vArray = NanohurtzSplit(vFile)
  xlApp.Cells(1, i).Resize(UBound(vArray) - LBound(vArray) + 1, 1).Value = xlApp.Transpose(vArray)
  i = i + 1
 Next

 xlApp.Visible = True

Function NanohurtzSplit(vFilePath)
 Dim FSO, TS, FileCont, vContents, i
 Set FSO = CreateObject("Scripting.FileSystemObject")
 Set TS = FSO.OpenTextFile(vFilePath, 1)
 FileCont = TS.ReadAll
 TS.Close
 Set TS = Nothing
 Set FSO = Nothing
 vContents = Split(FileCont, "/")
 For i = LBound(vContents) +1 To UBound(vContents)
  vContents(i) = "/" & vContents(i)
 Next
 NanohurtzSplit = vContents
End Function

Open in new window

0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 28732683
Fine work, Mr. Vidas.  I was just about to jump in myself, but I see it's already well-covered :)
0
 
LVL 35

Expert Comment

by:mvidas
ID: 28733324
Well, VBS and Excel combined, I can't pass it up :) I even got to throw in an application.transpose!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:NanohurtzChrome
ID: 28926886
HOT DOG!!!! <ahem> excuse me... hehe. That is some is some extremely FINE scripting there mvidas. Blew my hair back - EXACTLY what I was looking for.

You just saved me DAYS of work. If I could give you 1000 points I would. Many, MANY thanks!
0
 

Author Closing Comment

by:NanohurtzChrome
ID: 31707758
A scripting ninja he is!
0
 
LVL 35

Expert Comment

by:mvidas
ID: 28941213
Glad to help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question