View Single Post
Old 12-11-2007   #1 (permalink)
Kryten


 
 

More text processing.

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


I already have a program to do this in Excel VBA but I like the idea
of running it in PoSH.

I've been playing around with where-object, select-object etc and have
no problem reading in the file
and iterating line by line doing something like foreach ($line in
$file) { if $line ....} looks for matching patterns then writes it to
a file. The problem is that I don't understand how to format the
output into what I need. Invariably I end up with something that looks
like :-

DSC RLI
------- -----
50000
120
50001
140
50002
120

Would be grateful for any pointers.

Thanks,
Stuart
My System SpecsSystem Spec