Solved

Help change script to read file with ~ in the delimeter

Posted on 2011-03-15
2
201 Views
Last Modified: 2012-05-11
Hello
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)
Else
  WScript.Echo "No filename specified."
  WScript.Quit
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
oInfile.Close
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)
   oOutFile.Write(aChunks(LBound(aChunks)))
   oOutFile.Write(aChunks(i))
   oOutFile.Write(aChunks(UBound(aChunks)))
   oOutFile.Close
   set oOutFile = Nothing
Next

' Cleanup and end
Set oFSO = Nothing
Wscript.Quit

' 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
file1.txt
file2.txt
0
Comment
Question by:Navarre_EDI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
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 "*".

Sandip
0
 

Author Comment

by:Navarre_EDI
ID: 35147243
Hello

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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Six Sigma Control Plans

734 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