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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can anyone please tell me why i can not find ID  investorCoolGrid inside the jsp page? 1 20
Best Way to remove the port from a URL? 15 38
Jquery keyup 4 20
Clear Filter 8 41
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

831 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