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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
document.write() deleting all existing HTML 5 50
Create Consolidation Sheet 3 38
function parameter and using that as array 15 23
CORS Error from Chrome, but FireFox is OK 1 79
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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)

856 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