Solved Count no. of lines in multiple text files

December 28, 2011 at 00:59:41
Specs: Windows XP
Hi guys, is it possible to count the number of lines in multiple text file and output the number of lines for each text file into 1 single text file. This is the current script I have but it counts all the lines(excluding the first line) and output into 1 result. What I want is Eg: file A = 90 lines file B = 85 lines
Not total = 175 lines


setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%t in ('dir/b *.txt') do (
for /f "tokens=* skip=1 delims= " %%a in (%%t) do (
set /a N+=1
)
)
echo total is !N!>>total.txt


See More: Count no. of lines in multiple text files

Report •

#1
December 28, 2011 at 13:49:34
✔ Best Answer
Here's a quick and lazy - hope you can amend it to suit your purpose. The script is almost untested, hope it helps.

@echo off>%temp%\lines.txt
cls
setlocal enabledelayedexpansion

for /f "tokens=*" %%t in ('dir/b *.txt') do (

if !lines! gtr 0 echo !filename!=!lines! lines.>>%temp%\lines.txt&&set lines=

for /f "tokens=* skip=1" %%a in (%%t) do (
    set filename=%%t
    set /a N+=1
    set /a lines+=1
   )

if !lines! gtr 0 echo !filename!=!lines! lines.>>%temp%\lines.txt&&set lines= 
)

echo.>>%temp%\lines.txt
echo total is !N!>>%temp%\lines.txt

type %temp%\lines.txt


Please come back & tell us if your problem is resolved.


Report •

#2
December 28, 2011 at 18:57:12
Hi Wahine,
it works perfectly! Thanks for the help again :) Cheers!
Thanks
Wei

Report •
Related Solutions


Ask Question