Я получил файл со следующим шаблоном:
10:15:16:290 53123
10:15:16:290 ra-agi Trace: Sending Query Request message to application gateway host. 10:15:16:290 ra-agi Trace: ApplicationGatewayID = 5001 10:15:16:290 ra-agi Trace: InvokeID = 5456787
10:15:16:493 5456787
10:15:16:306 ra-agi Trace: Sending Query Request message to application gateway host. 10:15:16:306 ra-agi Trace: ApplicationGatewayID = 5000 10:15:16:306 ra-agi Trace: InvokeID = 132
10:15:16:337 132
10:15:16:509 54565
10:15:16:337 ra-agi Trace: Sending Query Request message to application gateway host. 10:15:16:337 ra-agi Trace: ApplicationGatewayID = 5001 10:15:16:337 ra-agi Trace: InvokeID = 54565
10:15:16:400 5456512
10:15:16:384 ra-agi Trace: Sending Query Request message to application gateway host. 10:15:16:384 ra-agi Trace: ApplicationGatewayID = 5000 10:15:16:384 ra-agi Trace: InvokeID = 5456512
10:15:16:603 5
10:15:16:400 ra-agi Trace: Sending Query Request message to application gateway host. 10:15:16:400 ra-agi Trace: ApplicationGatewayID = 5001 10:15:16:400 ra-agi Trace: InvokeID = 5
10:15:16:493 ra-agi Trace: Sending Query Request message to application gateway host. 10:15:16:493 ra-agi Trace: ApplicationGatewayID = 5000 10:15:16:493 ra-agi Trace: InvokeID = 3124
10:15:16:509 3124
10:15:16:509 ra-agi Trace: Sending Query Request message to application gateway host. 10:15:16:509 ra-agi Trace: ApplicationGatewayID = 5000 10:15:16:509 ra-agi Trace: InvokeID = 95787812
10:15:16:525 95787812
10:15:16:509 ra-agi Trace: Sending Query Request message to application gateway host. 10:15:16:509 ra-agi Trace: ApplicationGatewayID = 5001 10:15:16:509 ra-agi Trace: InvokeID = 9578781
10:15:16:728 9578781
10:15:16:712 62
С помощью моего кода я пытаюсь отсортировать короткие строки по номеру с помощью следующего кода:
$result = [System.IO.File]::ReadLines($file).Trim() |
Group-Object @{Expression = { [int] $_.Substring($_.Length - 8)} } | # group by InvokeID (last 8 characters of the shortline)
Where-Object { $_.Count -eq 2 } | # select only groups with two items in it (one long and one short line)
My Проблема в том, что числа не всегда имеют одинаковую длину. Как я могу сделать это динамически c ?. Я получил цифры от 1 до git до 8 цифр.