Welcome, guest | Sign In | My Account | Store | Cart
::counts lines and words in a text file
@echo off

set /a cnt=0,lin=0
for /f "usebackq tokens=*" %%a in (%1) do ( set /a lin+=1
  for  %%b in (%%a) do  set /a cnt+=1 
)  
echo  File: %~nx1  words: %cnt%  lines: %lin%

pause

Diff to Previous Revision

--- revision 1 2017-04-27 16:21:52
+++ revision 2 2017-04-28 08:22:08
@@ -1,9 +1,10 @@
 ::counts lines and words in a text file
 @echo off
-setlocal enabledelayedexpansion
+
 set /a cnt=0,lin=0
 for /f "usebackq tokens=*" %%a in (%1) do ( set /a lin+=1
   for  %%b in (%%a) do  set /a cnt+=1 
 )  
-echo  File: %~nx1  words: !cnt!  lines: !lin!
-pause 
+echo  File: %~nx1  words: %cnt%  lines: %lin%
+
+pause

History