list of end points from GC and array

I have a datafile with a list of “endpoints.”  Each endpoint has 8 readings.  they should be nicely arranged.  But i still want to create an array of the endpoint from the datafile so that i can scan the database a second time and get the readings for each endpoint.  I guess i could hardcode that, or put the endpoints into a database or configuration file that i share, but what i did was this:

  1. get-content on the remote file and store it  in $lines
  2. foreach line, split the line into the date, the endpoint and the reading
  3. If in the array, do nothing otherwise add the endpoint to the array $endpoints.  I could add all the endpoints and do UNIQUE and i have no idea if that would be performant.
  4. foreach endpoint in endpoints, write the endpoint to console, and next for each line in $lines, match the endpoint in the line and if found, split the line to get the reading  and write it.
  5. Output the last line.  If line is only used inside the foreach, it will not display after the loop is closed.  Therefore, declare it at the top and we will have it updated each time.

Finally, we do a lot of ‘split’.  We can either split to an array, or split to a implcit array or split and return only the desired item.

$array = $line.split(“,”)’ $array[2]
($a,$b,$c) = $line.split(“,”); $c

We are reading the same data 21 times.  I BET there is a more efficient way to do this, but the blog is mostly about the split options.

$endpoints = @()
$line = $null
$lines = gc "\\db-quartz\c$\scripts\biglogs\BigNeptureB.txt"

foreach ($line in $lines){
 ($a, $b, $c) = $line.split(",")
     if ($endpoints -contains $b) {
        } else {
         $endpoints += $b
     } # end if/else
 } # end foreach lines

foreach ($endpoint in $endpoints){
     foreach ($line in $lines){
        if ($line.contains("$endpoint")){
        } # end if
     } # end foreach line
   } # end foreach $endpoint
$line # declared above
This entry was posted in Uncategorized. Bookmark the permalink.