Reputation: 45
I have the following String, not separated by lines (it is the output of a Posh-SSh connection):
Active : Cumulative : Peak Concur : Inactive
----------------------------------------------
AnyConnect Client : 959 : 1652 : 1028 : 31
SSL/TLS/DTLS : 959 : 1652 : 1028 : 31
Site-to-Site VPN : 5 : 35 : 5
IKEv2 IPsec : 2 : 24 : 2
IKEv1 IPsec : 3 : 11 : 3
---------------------------------------------------------------------------
Total Active and Inactive : 995 Total Cumulative : 1687
---------------------------------------------------------------------------
---------------------------------------------------------------------------
Tunnels Summary
---------------------------------------------------------------------------
Active : Cumulative : Peak Concurrent
----------------------------------------------
IKEv1 : 3 : 11 : 3
IKEv2 : 2 : 24 : 2
IPsec : 7 : 45 : 9
AnyConnect-Parent : 990 : 1652 : 1028
SSL-Tunnel : 912 : 2698 : 962
DTLS-Tunnel : 857 : 2813 : 889
What I want to extract is "AnyConnect Client : 959 : ", indeed, "959" is the string I need.
With this expression on Select-String I get the match, but I just need the chars after the pattern, let's say 50 characters (and after that I will extract the numbers):
Select-String -Pattern "(?=.*AnyConnect Client).*"
Thanks!
Upvotes: 1
Views: 125
Reputation: 174465
Sounds like you need a look-behind ((?<=PATTERN)
) instead of a look-ahead ((?=PATTERN)
):
$String |Select-String -Pattern "(?<=.*AnyConnect Client\D*)\d+" |ForEach-Object {$_.Matches.Value}
Upvotes: 2