[BATCH] Count number of lines in a text file
Solved
-Tyrael-
Posted messages
103
Status
Member
-
Hakim -
Hakim -
Hello everyone,
There are many topics, and I've (almost) found my happiness.
I still have a problem that I can't solve.
The line count is incorrect. I'm missing more than 30 lines.
Here's my code:
The file is a *.log file; I don't know if that changes anything compared to a *.txt
It has 191 lines when opened with Notepad and 201 when opened with Notepad++.
Configuration: Windows XP / Safari 536.11
There are many topics, and I've (almost) found my happiness.
I still have a problem that I can't solve.
The line count is incorrect. I'm missing more than 30 lines.
Here's my code:
@echo off set nb=0 set /p fichier="Drag your file here" for /f "tokens=*" %%i in ('type %fichier%') do ( set /a nb+=1 ) echo %nb% pause>nul The file is a *.log file; I don't know if that changes anything compared to a *.txt
It has 191 lines when opened with Notepad and 201 when opened with Notepad++.
Configuration: Windows XP / Safari 536.11
7 answers
-
hello
try this to count the linesfind /v /c "" < file
-
I think I have the solution:
@echo off setlocal enabledelayedexpansion set nb=0 set /p fichier="Drag your file here" for /f "delims=" %%a in (%fichier%) do ( set /a nb=!nb!+1 ) echo %nb% pause>nul endlocal
-
hello,
if I want to count the number of lines in several TXT files, how would I do that please?
I did it like this but it doesn't work
@Echo OFF
for /f "delims=;" %%a in (fichier.txt) do (
for /f "delims=" %%i in ('type %%a.txt') do ( set Compt=0 set /a Compt+=1
echo %Compt% >>resultats.txt
)
)
pause -
Indeed, I have the right number of lines (the one from np++) thank you :)
How can I store this number in a variable?
The end goal is to retrieve the first 3 and the last 3 lines of the file to put them in a log file. -
this loop ignores empty lines in the file
for /f "tokens=*" %%i in ('type %file%') dopass through a loop to store the result in a variableC:> type f1.txt aa bb cc dd C:> find /v /c "" <f1.txt c:=""> for /f %a in ('find /c /v "" ^< f1.txt') do @set l=%a C:> echo %l% 7 C:</f1.txt> -
Perfect !!
(just needed to use %%a instead of %a)
Thank you very much!
Just need to get my lines and it's all good. -
yes, %a in interactive mode, %%a in a .bat file