Author Posts

January 1, 2012 at 12:00 am

by JonathanGrocott at 2013-03-04 18:41:32

What i have is this:

# Returns the Total Run Time from .lst files in directory $inputpath #
$input_path = ‘C:\RUN_TIME_TEST\*.lst’
$output_file = ‘C:\RUN_TIME_TEST\Test.csv’
$items = 'TOTAL.......\d\d:\d\d:\d\d'
$items2 = 'GD_SequenceNumber=\d*'
$regex = $items
$regex2 = $items2

select-string -Path $input_path -Pattern $regex2 -List | % { $_.Matches } | % { $_.Value } > $output_file

select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } >> $output_file

What this returns:

GD_SequenceNumber=100
GD_SequenceNumber=40
GD_SequenceNumber=50
GD_SequenceNumber=60
GD_SequenceNumber=70
GD_SequenceNumber=80
GD_SequenceNumber=90
TOTAL 00:08:15
TOTAL 00:07:21
TOTAL 00:08:12
TOTAL 00:07:34
TOTAL 00:00:52
TOTAL 00:00:54
TOTAL 00:00:52

What i need is the Regex2 return followed by the Regex1 return, from each input file comma delimited. How do i format this associativity?

Thanks!

by mjolinor at 2013-03-05 06:00:26

gci $input_path |
% {((gc $_ | select-string -Pattern $regex,$regex2).Matches | select -ExpandProperty value) -join ','}