「grep」した後、PowerShell で文字列を分割するのに苦労しています。1 時間ごとの Web ログから最大 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- in-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]
ありがとう!