Help change script to read file with ~ in the delimeter

Posted on 2011-03-15
Last Modified: 2012-05-11
I am using this scrip to break up file 1 that I included into mult file based on ST and SE with delimeter *
Now I have a file that comes in with delimeter ~ how do I change the script to work for this file 2

Here the script

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

' Get input file name from command line parm
If (WScript.Arguments.Count > 0) Then
  sInfile = WScript.Arguments(0)
  WScript.Echo "No filename specified."
End If

' Create file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Generate time stamp for output file naming
sStamp = fTimeStamp()

' Open input file for reading
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
sData = oInfile.ReadAll
Set oInfile = Nothing

' Split input into "chunks" around SE~/SE~ pairs
sData = Replace(sData, "ST~850~", "[SPLIT]ST~850~")
sData = Replace(sData, "GE~", "[SPLIT]GE~")
aChunks = Split(sData, "[SPLIT]")

' Renumber "SE~" sequences as needed
Set oRegExp = New RegExp
oRegExp.Global = True
oRegExp.IgnoreCase = False
oRegExp.Pattern = "(SE~\d+~)(\d+)(~|\r\n)"
Set oFound = oRegExp.Execute(aChunks(UBound(aChunks)))
oRegExp.Pattern = "GE~\d+~"
aChunks(UBound(aChunks)) = oRegExp.Replace(aChunks(UBound(aChunks)), "GE~1~")

' Get path for output files
Set oTemp = oFSO.Getfile(sInfile)
'sDate = Year(Now()) & Right("0" & Month(Now()), 2) & Right("00" & Day(Now()), 2) & Hour(Now()) & Minute(Now()) & Second(Now())

'sPath = oTemp.ParentFolder
sPath = "C:\Program Files\TIE Commerce\eVision\Apple_Sims_Orders\single_files"
Set oTemp = Nothing

' Process input file, split desired chunks to seperate files
iFile = 0
For i = LBound(aChunks)+1 To UBound(aChunks)-1
   iFile = iFile + 1
   Set oOutFile = oFSO.OpenTextFile(sPath & "\" & "Split_" & sStamp & "_" & Right("000" & iFile, 3) & ".asingle", ForWriting, True)
   set oOutFile = Nothing

' Cleanup and end
Set oFSO = Nothing

' Build a time stamp in YYYYMMDD_HHMMSSmm format
Function fTimeStamp()
    iSeconds = (Hour(Now) * 3600) + (Minute(Now) * 60) + Second(Now)
    iMilliseconds = Timer() - iSeconds
    iMilliseconds = Fix(iMilliseconds * 100)
    iDate = (Year(Now) * 10000) + (Month(Now) * 100) + Day(Now)
    iTime = (Hour(Now) * 1000000) + (Minute(Now) * 10000) + (Second(Now) * 100) + iMilliseconds
    fTimeStamp = iDate & "_" & Right("0" & iTime, 8)
End Function
Question by:Navarre_EDI

Accepted Solution

sshah254 earned 500 total points
ID: 35144111
The easiest thing is to do this on line 23

sData = Replace(sData, "~", "8")

and keep everything the same.

Of course, presuming that the data set does not contain any "*".


Author Comment

ID: 35147243

The questions was incomplete

The script above break the file up based on ST to SE and delimeter ~

I have a file coming in that has delimeter *. How do I change my script to break up the files using *

Help Please

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now