title: VBScript to Remove characters from Txt file except particular characters and align the result properly in single line
body: <p>I am trying to write VBScript to edit a text file, keep only relevent set of numbers in each line and remove all other characters.</p>
  
  <p>Here is the text file</p>
  
  <pre class="lang-none prettyprint-override"><code>Receive: Return Code: 0x00000000
  00000000  08 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  E0 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  07 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  81 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  85 .              
  
  
  Receive: Return Code: 0x00000000
  00000000  32 2               
  
  
  Receive: Return Code: 0x00000000
  00000000  E5 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  1D .               
  
  
  Receive: Return Code: 0x00000000
  00000000  40 @               
  
  
  Receive: Return Code: 0x00000000
  00000000  09 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  05 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  44 D               
  
  
  Receive: Return Code: 0x00000000
  00000000  20                          
  
  
  Receive: Return Code: 0x00000000
  00000000  01 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  00 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  12 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  03 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  00 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  08 .               
  
  
  Receive: Return Code: 0x00000000
  00000000  E0 .           
  </code></pre>
  
  <p>I need only Numbers starting from E0 to 1D (eight characters from E0) as highlighted in above txt file., and ignore all other until E0 appears again.</p>
  
  <p>Here is the script I wrote</p>
  
  <pre><code>Option explicit
  Dim objFSO,objFile,strText,strNewText,strNewText1,strNewText2,strNewText3
  Dim strNewText4,strNewText5,Newfile,strNewText6,strNewText7
  Const ForReading = 1
  Const ForWriting = 2
  
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile("Path\file.txt", ForReading)
  strText = objFile.ReadAll
  objFile.Close
  
  strNewText = Replace(strText,"00000000"," ")
  strNewText1 = Replace(strNewText,"Receive: Return Code: 0x"," ")
  strNewText2= Replace(strNewText1,"Receive:"," ")
  strNewText3 = replace(strNewText2,"Return Code: 0x"," ")
  strNewText4 = replace(strNewText3,","," ")
  strNewText5 = replace(strNewText4,"."," ")
  
  Dim illegalChar , Result
  Set illegalChar= new Regexp 
  illegalChar.ignoreCase = True
  illegalChar.Global = True
  illegalChar.pattern = "a-zA-Z0_9"
  Result = IllegalChar.Replace(strNewText5," ")
  
  strNewText6 = Result 
  Set objFile = objFSO.OpenTextFile("Path\result.txt", ForWriting)
  objFile.WriteLine strNewText6
  objFile.Close
  </code></pre>
  
  <p>After running above script result is like</p>
  
  <pre class="lang-none prettyprint-override"><code>08                                                                 
  
  
  
  E0                                                                 
  
  
  
  07                                                                 
  
  
  
  81                                                                 
  
  
  
  85                                                                 
  
  
  
  32 2               
  
  
  
  E5                                                                 
  
  
  
  3A :               
  
  
  
  42 B               
  
  
  
  09                                                                 
  
  
  
  05                                                                 
  
  
  
  2D -               
  
  
  
  05                                                                 
  
  
  
  01                                                                 
  
  
  
  00                                                                 
  
  
  
  12                                                                 
  
  
  
  03                                                                 
  
  
  
  00                                                                 
  
  
  
  08                                                                 
  
  
  
  E0
  </code></pre>
  
  <p>This is my desired output:</p>
  
  <pre>
  E007818532E53A42
  E007818532E52C43
  ...
  </pre>
  
  <p>We need to remove all the characters after the first two digits in each line. Later we can arrange the number starting from E0 for the next 7 double digits in each line and remove all other character until E0 is found again.</p>