Solved

Help change script to read file with ~ in the delimeter

Posted on 2011-03-15
2
194 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
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
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…

758 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