Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
Credits 11,386 Posts 4,938 Joined 2006-07-23 17:10 19-year member UID 59080
Status Offline
Run the following batch script. Enter the file name to be checked, and after pressing Enter, the number of words per line will be displayed. Words are strings separated by spaces or horizontal tabs.
@Echo Off&SetLocal EnableDelayedExpansion
set/p file=Please input the file you want to check:
if not defined file (echo Error&pause&exit/b)
if not exist "%file%" (echo Error&pause&exit/b)
for /f "delims=: tokens=1*" %%a in ('findstr /n .* "%file%"') do (
set b=&set a=%%b
if not "!a!"=="" (
for %%h in (!a!) do set /a b+=1
echo/Line %%a:!b! words
) else (echo/Line %%a:0 words)
)
pause
Credits 11,386 Posts 4,938 Joined 2006-07-23 17:10 19-year member UID 59080
Status Offline
Re bza2006:
!a! is equivalent to %a%, which means referencing the value of variable a. But it needs to use variable delay (setlocal enabledelayedexpansion) in for, so use! instead of % to reference its value.
You can take a look at the following related explanations: