Regex Formatting Help

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 3 months ago.

  • Author
    Posts
  • #5624

    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 ','}

You must be logged in to reply to this topic.