Filter text output in powershell.

In powershell I am calling an executable file and capturing the output in the following format:

A1         A111        B111      C111
              A222        B222      C222
              A333        A333      C333
B1         B111        B111      B111
              B222        B222      B222
              B333        B333      B333
C1         C111        C111      C111
              C222        C222      C222
              C333        C333      C333

Open in new window


This is returned as string which I capture into a variable, what I need is a nice way to filter this data by column1 (where all blank column data under column 1 equals that of the value above), and then create an array of the filtered data so I can access each row/column data as required. The spacing between the columns is multiple plain spaces - but to spice things up a bit column 2 includes data with spaces (but only single spaces so hopefully this should be do'able).
Blowfelt82Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Blowfelt82Author Commented:
Note: The formatting has got messed up - these columns should form aligned columns.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
If the columns are aligned, we could use a fixed column approach (using pre-defined column positions), but I decided to be more flexible.
$data = @"
A1         A111        B111      C111
              A222 +       B222      C222
              A333        A333      C333
B1         B111        B111      B111
              B222        B222      B222
              B333        B333      B333
C1         C111        C111      C111
              C222        C222      C222
              C333        C333      C333
"@ -split "`n" 

$prior = $null
$data -replace '\s\s+', '|' |
  ConvertFrom-Csv -Delimiter '|' -Header c1, c2, c3, c4 |
  % {
    if (!$_.c1) { $_.c1 = $prior }
    $prior = $_.c1
    $_    
  }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Blowfelt82Author Commented:
Worked like a charm - thanks for your time.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.