"Kryten" <Kryten68@xxxxxx> wrote in message
news:fd2969ca-ee58-48c3-8d66-3e2f1f7462bd@xxxxxx
Quote:
> Hi,
> I'm trying to turn a .txt which contains thousands of lines of this:-
>
> DSC 50000
> FLEN 5
> DSP DN
> RRPA NO
> RLI 120
> NPA
> NXX
> DSC 50001
> FLEN 5
> DSP DN
> RRPA NO
> RLI 140
> NPA
> NXX
> DSC 50002
> FLEN 5
> DSP DN
> RRPA NO
> RLI 120
> NPA
> NXX
>
> Into something that looks like this:-
>
> DSC RLI
> ------- ----
> 50000 120
> 50001 140
> 50002 120
>
Here's another solution that uses the very useful switch -regex -file
feature:
27> function newObj {$obj = new-object psobject; $obj | add-member
NoteProperty DSC '' -pass | add-member NoteProperty RLI '' -pass}
28> switch -regex -file .\foo.dat {'^DSC\s+(\d+)' {$obj = newObj; $obj.DSC =
$matches[1]} '^RLI\s+(\d+)' {$obj.RLI = $matches[1];$obj}}
DSC RLI
--- ---
50000 120
50001 140
50002 120
--
Keith