파일의 개별 단어 인스턴스를 계산하는이 스크립트를 적용하고 있습니다. 현재 문자열을 나타내는 입력 $s
변수가 계산 될Powershell에서 파일 내용을 읽으려면 어떻게해야합니까?
$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
}
는 하드이다. 각 문서를 내 $srcFiles
경로로 가져 와서 각각에 대해 계산을 실행하고 싶습니다. 그러나 $s = $docs
은 제목이 아닌 문서 내용을 계산합니다. 어떻게해야합니까? 나는이 문제를 서식을 찾아야한다
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
:
또한이 $W | group | sort name | ft name,count -AutoSize
다음과 같은 오류를 반환? TechNet에서 기본 서식 정보를 찾을 수 없었습니다. 이 코드가 원래 제공 한 site은 어떻게 작동하게 만들지, 어떤 기본 형식을 재정의했는지에 대해 언급하지 않습니다. 나는 그것이 다르게 파이프해야 할 수도 있습니다 용의자,하지만 난 더 나은 정확한 오류를 이해할 필요가 어디서부터 사냥을 시작 알아야합니다.
또는 V3에서'Get-Content -Raw'를 사용하면 모든 파일 내용이 포함 된 단일 문자열을 반환 할 수 있습니다. v1/v2에서는'[IO.File] :: ReadAllText()'를 사용합니다. :-) –
해당 매개 변수에 대해 알지 못했습니다. 굉장해! –