Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

VB Script needed

Hello,

I am needing a script to open a file, search for two different things in the text, then write to the file based on what it finds.  The file that needs to be opened is located in the "c:\tpnt\tester\" directory and the file name is "TP600.cur".  It needs to search first for "iisnaic.com" and if it finds that anywhere in the file quit.  If it does not find that it needs to search for "DEST#*" the * will be a single digit 0-9 and it will need to return what the highest digit is and then write the following;

DEST#*="IBT FBI" EMLDMN trace.xfm trace.xfm SMTP 1
DEST#*:REXX=
EML_DEST#*.CONTENTTYPE=Content-type: application/octet-stream ; name=efts.sub
EML_DEST#*.FROM:0=arlington@IBT.com
EML_DEST#*.MULTIPART=FALSE
EML_DEST#*.SERVER:0=iisnaic.com
EML_DEST#*.SUBJECT:0=%ORI(0)% + "." + %TCN(0)% + ".APPLICANT"
EML_DEST#*.TO:0=livescan@iisnaic.com

All of the * will need to be replaced with the next sequential number from above.  So if the highest it returns is DEST#3 I need it to write each * as a 4.  

Any help with this would be greatly appreciated.
0
hoshie329
Asked:
hoshie329
  • 5
  • 4
1 Solution
 
Bill PrewCommented:
Please provide a sample input file, and the result output file you would want.

~bp
0
 
hoshie329Author Commented:
The file name for both will be the same TP600.cur.  This will be run on multiple machines with different configs.  The compareable fields will be the DEST# fields.  I have attached a sample TP600.cur file.  The file will be quite a bit longer than this, I had to remove quite a bit that was confidential.
tp600.cur.txt
0
 
Bill PrewCommented:
So in a given input file, all the DEST#* values will be the same?  So in the case of the file you provided they are all DEST#0.  Once we see one that has a vlaue, do we have to look at every other one, or are they all the same?

Is it safe to assume that all places where DEST#0 occur in the file, they get replaced by DEST#1?

~bp
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hoshie329Author Commented:
Not Necessarily, some of the machines have multiple destinations.  All that we really need it to find is what the last sequential one is since we do not want to modify anything that is already set up.  So if we are able to set it up to search for DEST#0 and if it finds it anywhere go on to search for DEST#1 and so on until it does not find the DEST#* that we are looking for that would work.  They will always be in sequential order so if there is a DEST#2 there has to be a DEST#1 and DEST#0.  For our software to recognize it as being valid the one we are adding has to be the next one in sequential order.
0
 
Bill PrewCommented:
What's the highest DEST#* that can exist in the file?

Once we find the "next" number to use, what are we doing to the file?  Origianlly I read it as we are changing ALL the DEST#* in the file to DEST#n, where n is the next available number.  But if there are multiple numbers already in the file I wouldn't think you'd be changing them all to the same number.  Or are we adding new lines to the end of the file, leaving the rest as is?  Not clear on what you want to output to be.

~bp
0
 
hoshie329Author Commented:
The highest number would be 8 which would make our highest number to be used 9.  

Once we find the next number we are going to write the following lines at the end of the file.  

DEST#*="IBT FBI" EMLDMN trace.xfm trace.xfm SMTP 1
DEST#*:REXX=
EML_DEST#*.CONTENTTYPE=Content-type: application/octet-stream ; name=efts.sub
EML_DEST#*.FROM:0=arlington@IBT.com
EML_DEST#*.MULTIPART=FALSE
EML_DEST#*.SERVER:0=iisnaic.com
EML_DEST#*.SUBJECT:0=%ORI(0)% + "." + %TCN(0)% + ".APPLICANT"
EML_DEST#*.TO:0=livescan@iisnaic.com

For all of the * is where we will put the next number in the sequence.  Yes we will be leaving the rest of the file as it was before.
0
 
Bill PrewCommented:
Okay, I think this should get the job done.  Save as a VBS, and then run like this:

cscript EE27869384.vbs in.txt out.txt

or

cscript EE27869384.vbs in.txt

In the first case in.txt will be read, and the chnaged version of the file (with the new lines) will be placed in out.txt.  This is handy for testing.  In the second example it will read the input file in.txt, and since no other file was specified, it will overwrite in.txt with any needed changes.

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

' Get input file name from command line parm, if 2 parms entered
' use second as new output file, else rewrite to input file
If (WScript.Arguments.Count > 0) Then
  sInfile = WScript.Arguments(0)
Else
  WScript.Echo "No filename specified."
  WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
  sOutfile = WScript.Arguments(1)
Else
  sOutfile = sInfile
End If

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

' Read entire input file into a variable and close it
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
sData = oInfile.ReadAll
oInfile.Close
Set oInfile = Nothing

' Don't process the file if it contains "iisnaic.com"
If Instr(1, sData, "iisnaic.com", vbTextCompare) = 0 Then
   ' Make sure we can find a DEST# in the current file
   iDest = InstrRev(sData, "DEST#", -1, vbTextCompare)
   If iDest > 0 Then
      ' Calculate dest number to use next
      iNext = CInt(Mid(sData, iDest+5, 1)) + 1
      ' Write file with any changes made
      Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True, TriStateUseDefault)
      oOutfile.Write sData
      oOutfile.WriteLine Replace("DEST#[NEXT]=""IBT FBI"" EMLDMN trace.xfm trace.xfm SMTP 1", "[NEXT]", iNext)
      oOutfile.WriteLine Replace("DEST#[NEXT]:REXX=", "[NEXT]", iNext)
      oOutfile.WriteLine Replace("EML_DEST#[NEXT].CONTENTTYPE=Content-type: application/octet-stream ; name=efts.sub", "[NEXT]", iNext)
      oOutfile.WriteLine Replace("EML_DEST#[NEXT].FROM:0=arlington@IBT.com", "[NEXT]", iNext)
      oOutfile.WriteLine Replace("EML_DEST#[NEXT].MULTIPART=FALSE", "[NEXT]", iNext)
      oOutfile.WriteLine Replace("EML_DEST#[NEXT].SERVER:0=iisnaic.com", "[NEXT]", iNext)
      oOutfile.WriteLine Replace("EML_DEST#[NEXT].SUBJECT:0=%ORI(0)% + ""."" + %TCN(0)% + "".APPLICANT""", "[NEXT]", iNext)
      oOutfile.WriteLine Replace("EML_DEST#[NEXT].TO:0=livescan@iisnaic.com", "[NEXT]", iNext)
      oOutfile.Close
      Set oOutfile = Nothing
   End If
End If

' Cleanup and end
Set oFSO = Nothing
Wscript.Quit

Open in new window

~bp
0
 
hoshie329Author Commented:
All tests are going great with this.  Thank you!
0
 
Bill PrewCommented:
Welcome, thanks for the feedback.

~bp
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now