ファイル内の個々の単語のインスタンスをカウントするこのスクリプトを採用しています。
$txtPath = "c:\users\xxxxxx\desktop\tx"
$srcfiles = Get-ChildItem $txtPath -filter "*.txt*"
#
function wordCount ($docs) {
Write-Host "Processing Word Count: " $docs
$s = "I saw the cat. The cat was black."
",",".","!","?",">","<","&","*","=","`n","_" |% {$s = $s.replace($_,' ')} # Remove Chars
$w = $s.Split() |? {$_.Length -gt 0 } # Array of words, spaces removed
$w | select -Unique # Unique words
$w | group # Tally
$W | group | sort name | ft name,count -AutoSize # Sort and format
#>
}
#
ForEach ($doc in $srcfiles) {
Write-Host "Calling: " $doc.FullName
wordCount -docs $doc.FullName
}
$s
現在、カウントされる文字列を表す入力変数はハードコーディングされています。$srcFiles
パス内の各ドキュメントを取得して、それぞれのドキュメントをカウントしたいと思います。ただし、$s = $docs
ドキュメントの内容ではなく、タイトルの単語をカウントします。それ、どうやったら出来るの?
また、$W | group | sort name | ft name,count -AutoSize
次のエラーを返します。
out-lineoutput : The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not
in the correct sequence. This is likely caused by a user-specified "format-table" command which is conflicting with th
e default formatting.
+ CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
+ FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
フォーマットの問題はどこで探す必要がありますか?TechNetでデフォルトのフォーマット情報を見つけることができませんでした。そして、このコードが最初に由来したサイトは、それらがどのようにそれを機能させたか、またどのデフォルトフォーマットをオーバーライドしていたかについては言及していません。別の方法でパイプする必要があるかもしれませんが、正確なエラーをよりよく理解して、どこからハンティングを開始するかを知る必要があります。