2017-12-11 1 views
0

와 단어를 계산 5 번 이상 나타납니다 그것을 출력 단어 만 있습니다. 이게 내가 생각해 낸 것이지만 배열로 라인을 나누어 인쇄 할뿐입니다 ... 생각은?파일을 분석하고 난 후, 입력 파일을하는 스크립트를 만들려고하고 있어요 파워 쉘

clear-host 
write-host 

$file = 'file.txt' 

foreach ($word in (get-content $file)) 
{  
    $a = $word.split(" .,?()") 

    foreach ($occ in $a -ge 5) 
    { 
    ? -ge 5 (Write-Host $occ) 
    } 
} 
+0

https://blogs.technet.microsoft.com/josebda/2015/03/21/powershell-examples-counting-words-in-a-text-file/ 정확히 어떻게해야 당신 하고 싶습니다. –

+0

감사합니다. –

답변

0
$file = "file.txt" 

$contents = Get-Content -Path $file 

$words = $contents.split(" .,?()") | Where-Object {$_} # this removes any empties/spaces 

Write-Host "Grouped:" -ForegroundColor Cyan 
$words | Group-Object 

Write-Host "Filtered:" -ForegroundColor Cyan 
$words | Group-Object | Where-Object Count -GE 5