Welcome, guest | Sign In | My Account | Store | Cart

Returns number of lines and words (separed by spaces) of a text file dragged to the script. Does'nt count blank lines.

Batch, 10 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
::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
Created by Antoni Gual on Thu, 27 Apr 2017 (MIT)
Batch recipes (42)
Antoni Gual's recipes (16)

Required Modules

  • (none specified)

Other Information and Tasks