在我“grep”它之后,我很难让 PowerShell 拆分一个字符串。我真的很想从每小时的网络日志中获得 10 个最大值。
“Grep”有效,但我无法拆分它:
PS D:\Work\ps> D:\Work\ps\test\grep.ps1 方法调用失败,因为 [Microsoft.PowerShell.Commands.MatchInfo] 不包含名为“split”的方法。在 D:\Work\ps\test\grep.ps1:8 char:2 + $string.split($separator,0, $option) + ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
https://communary.net/2014/11/10/grep-the-powershell-way/ https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/17/using-the-split-method-在powershell/
##"[com.vendorStuff.utils.Stopwatch]"
$string = select-string "execution \:" "D:\logs\server.log" -ca
$separator = "execution \:"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$string.split($separator,1, $option)
#$data.Split("execution \:")[1]
重要的是要注意:我已经逃脱了:'执行:'我尝试过的几件事:
[string]$Data = sls 'execution \:' "D:\Work\ps\test\server.log" -ca
$data.split('execution \:')[1]
也:
$Data = (sls 'execution \:' "D:\Work\ps\test\server.log" -ca).tostring().split('execution \:')[1]
谢谢!