title: Using PowerShell to extract lines from multiple files
body: <p>I have come to a situation that I need to analyze data from log/text files.  There are hundreds of files, and some times tens of thousands of lines of data.  I am using PowerShell only because its available on my computer and from what I can tell should be adequate.  Just from using Google and finding topics here, I have managed to create a script that will parse multiple files for one specific label and extract that entire line of data.</p>
  
  <p>The problem is I would like to extract multiple lines of different data from the file, mainly the actual data I am looking for and the date.  It would also be nice if I could get the data extracted to an Excel file. Right now it's extracted to a text file and I just cut and paste to an Excel, then change the format from text to column with space delimited.</p>
  
  <p>Here is a sample of the text I am looking at.</p>
  
  <pre>
  3I  "MAC" "DATE" := 2016, 8, 1
  3I  "MAC" "TIME" := 3, 42, 56
  15F  "MAC" "ORGB" := -1.656704e-04, -1.878277e-04, -1.873876e-04, -1.659016e-04, -1.429739e-04, -1.786126e-04, -1.590039e-04, -2.246118e-04, -1.951066e-04, -2.158172e-04, -1.526934e-04, -1.560605e-04, -1.856570e-04, -2.192611e-04, -1.747964e-04
  15F  "MAC" "ORGP" := -1.657223e-04, -1.878391e-04, -1.874067e-04, -1.659254e-04, -1.429638e-04, -1.786519e-04, -1.590114e-04, -2.245719e-04, -1.950584e-04, -2.158372e-04, -1.526876e-04, -1.561122e-04, -1.855181e-04, -2.192713e-04, -1.748256e-04
  15F  "MAC" "OFF3" := -7.424393e-08, -1.599836e-07, 1.178269e-07, 3.231106e-07, -4.113245e-07, -4.851174e-07, 4.043978e-07, 3.279856e-07, 6.228656e-07, 1.257285e-07, 1.290027e-07, -1.727165e-07, 7.661874e-07, 1.182343e-07, 1.484092e-06
  15F  "MAC" "POST" := -1.897504e-06, 1.557098e-05, -1.367209e-05, -8.604270e-06, -1.810627e-06, 1.041628e-05, -6.231011e-06, 1.683000e-05, -1.059830e-05, 8.980048e-06, -1.064588e-06, -7.914769e-06, -1.680518e-05, 2.467031e-05, -7.863747e-06
  15F  "MAC" "OFF4" := -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00
  15F  "MAC" "PRID" := -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00, -1.000000e+00
  15I  "MAC" "SOPC" := -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
  </pre>
  
  <p>And here is the script I am using, which takes forever like about 30min, and ends up consuming all my RAM because its probably not the best way to do what I am trying to do.</p>
  
  <pre><code>$log = Get-Content "C:\Users\derekru\Documents\WS FTP Pro\MACBAC\MACSENS_*.txt;1"
  foreach ($line in $log) { 
      if ($line -like "*OFF3*") {
          $line | Out-File -FilePath "D:\Work\MACSENS\Graph\STP09\160801-171022.txt" -Append
      }
  }
  </code></pre>
  
  <p>Ultimately I would like to be able to extract the "Date", "Time", "ORGB", "ORGP", and "OFF3" from multiple files into an excel so it's formated</p>
  
  <pre>
  Date, Time, ORGB, the 15 data points, ORGP, the 15 points of data, OFF3, the 15 points of data...
  </pre>
  
  <p>on one Excel row.</p>