2013-01-22 42 views

回答

1

Windows批處理只有

這將枚舉的每一個字的文件,並顯示單詞和計數。

限制

  1. 批次線長度8191(Windows XP以上)的限制。適用於舊版操作系統的2047

腳本

@echo off 
setlocal EnableExtensions DisableDelayedExpansion 
for /f "delims=" %%A in (file.txt) do (
    set "_=%%A" 
    call :Expand_ 
) 

:: Display the Word and Count 
rem set word: 
for /f "tokens=2,3 delims=:=" %%X in ('set word:') do echo %%X = %%Y 
goto End 


:Expand_ 
:: Clean Special Characters 
set "_=%_:"=%" 
set "_=%_:^=%" 
set "_=%_:<=%" 
set "_=%_:>=%" 
set "_=%_:&=%" 
set "_=%_:|=%" 
:: Replace Whitespace 
set "_=%_: =%" 
:: Remove Plurals 
rem set "_=%_:'s=%" 
:: Clean Punctuation 
:WordLoop 
for /f "tokens=1,* delims=`[email protected]#$%%*()-_+=\[]{};:/?., " %%X in ("%_%") do (
    set ".=%%X" 
    call :Expand. 
    set "_=%%Y" 
) 
if defined _ goto WordLoop 
goto :eof 

:Expand. 
:: Count the Words 
if defined word:%.% (
    set /a "word:%.%+=1" 
) else (
    set "word:%.%=1" 
) 
goto :eof 


:End 
endlocal 
+0

我想象的只是閱讀文件,但你真是太好了!非常感謝你! – michaeluskov

+0

這是我的榮幸。由於它所需的只是我已經編寫的腳本的一些修改,所以沒有太多的工作。 **':)'** –