title: VBScript Read Text file for multiple indexes and output to a new index
body: <p>I’m looking for a vbscript that can read each line of an input file, locate a particular value or set of values, and output those values (sorted Ascending) into a new lin. The file is an index file for a batch of documents being pushed up into an EDM system.</p>
  
  <p>The values are those with the C1 tag, there can be between 0 values (do nothing) and a max of 5 values. I need to output the multiple values for this tag into a new C17 tag with a dash in-between them.</p>
  
  <p>Incoming File Example:</p>
  
  <pre><code>[REPORT]
  [BREAKDOC]
  [Y:TIF]
  [C1:222334444]
  [C1:333445555]
  [C1:444556666]
  [ENDBREAK]
  C:\PATH\TO\BATCH\IMAGES\IMG00001.TIF
  [BREAKDOC]
  [Y:TIF]
  [C1:999887777]
  [C1:888776666]
  [C1:777665555]
  [C1:666554444]
  [C1:555443333]
  [ENDBREAK]
  C:\PATH\TO\BATCH\IMAGES\IMG00002.TIF
  [BREAKDOC]
  [Y:TIF]
  [C1:123121234]
  [ENDBREAK]
  C:\PATH\TO\BATCH\IMAGES\IMG00003.TIF
  </code></pre>
  
  <p>Output File Example:</p>
  
  <pre><code>[REPORT]
  [BREAKDOC]
  [Y:TIF]
  [C1:222334444]
  [C1:333445555]
  [C1:444556666]
  [C17:222334444-333445555-444556666]
  [ENDBREAK]
  C:\PATH\TO\BATCH\IMAGES\IMG00001.TIF
  [BREAKDOC]
  [Y:TIF]
  [C1:999887777]
  [C1:888776666]
  [C1:777665555]
  [C1:666554444]
  [C1:555443333]
  [C17:555443333-666554444-777665555-888776666-999887777]
  [ENDBREAK]
  C:\PATH\TO\BATCH\IMAGES\IMG00002.TIF
  [BREAKDOC]
  [Y:TIF]
  [C1:123121234]
  [C17:123121234]
  [ENDBREAK]
  C:\PATH\TO\BATCH\IMAGES\IMG00003.TIF
  </code></pre>
  
  <p>This whole thing is part of a Batch Manager application, which can call a vbscript and run it on this file. When our vendor set up the system, they setup a few of these vbscripts, and I’ve one of these so as to provide a reference for setting up this particular script. I’m sure it’s pretty easy, I just don’t know the particular expression you'd need to put together in the last section of the script. </p>
  
  <pre><code>' Service variables for the operation of VBScriptLauncher
  Dim   fso, Fichier_AAD, Fichier_CFG, Fichier_OUT
  Const ForReading = 1, ForWriting = 2
  
  Set fso  = CreateObject("Scripting.FileSystemObject")
  
  If (WScript.Arguments.Named.Exists("AAD")) Then
    Fichier_AAD = WScript.Arguments.Named.Item("AAD")
  End If
  
  If (WScript.Arguments.Named.Exists("CFG")) Then
    Fichier_CFG = WScript.Arguments.Named.Item("CFG")
  End If
  
  If (WScript.Arguments.Named.Exists("OUTFILE")) Then
    Fichier_OUT = WScript.Arguments.Named.Item("OUTFILE")
  End If
  
  Set lecture = fso.OpenTextFile(Fichier_AAD,ForReading)
  Set ecriture = fso.CreateTextFile(Fichier_OUT,ForWriting)
  
  Do until lecture.AtEndOfStream
  
      '**************************
      '* reading from in file   *
      '**************************
      SLine = lecture.ReadLine
  
      'So long as the index C1 are not found, the category is rewritten in the output file
      pos = InStr(SLine,"[C1:")
      if pos = 0 then
          ecriture.WriteLine (sLine )
      else
  
          'The index C1 is found, it is rewritten in the AAD output file and then exploited
          ecriture.WriteLine (sLine)          
  
          sLine = UCase(sLine)
          taille=len(sLine)
          mois=mid(sLine,8,2)
          annee=mid(sLine,11,4)
  
          sLine = "[C18:" &amp; mois &amp; "]"
          ecriture.WriteLine (sLine)
  
          if right(annee,1)="]" then
          sLine = "[C19:" &amp; annee 
          ecriture.WriteLine (sLine)
          else
          sLine = "[C19:" &amp; annee &amp; "]"
          ecriture.WriteLine (sLine)
          end if
      end if
  
  Loop    
  </code></pre>
  
  <p>Any questions or additional info needed, just ask and I will do my best to deliver.</p>
  
  <p>Thanks in advance!</p>