FIND /C "*" *.txt
Is there a way to enter wildcards into FIND? Or is there a better way
to get total number of lines, with or without find? Thanks!
find /c /v "" < file.txt
but it has a bug which returns one line too few (I think when two blank
lines are at the end of a file).
This works though.
@echo off
for /f "delims=:" %%a in ('findstr /n "^.*$" file.txt') do set num=%%a
64} How to count the number of lines in a file, empty lines inclusive?
157253 Mar 9 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
> bigdave wrote:
>> I'm attempting to create a bat file which will return the total number
>> of lines in a .txt file.
>
> 64} How to count the number of lines in a file, empty lines inclusive?
> 157253 Mar 9 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
> tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
>
> All the best, Timo
You might like to note my comment about using find, to add to your FAQ.
find /c /v "" < file.txt
It has a bug which returns one line too few when two blank
lines are at the end of a file.
> You might like to note my comment about using find, to add to your FAQ.
Thank you for the welcome notification. Gladly. I have added to the
item
Other options:
@echo off & setlocal enableextensions
:: Make a test file
for %%f in (myfile.txt) do if exist %%f del %%f
for %%f in (first second third fourth) do (
echo This is the %%f line>>myfile.txt)
echo.>>myfile.txt
for %%f in (sixth seventh eight) do (
echo This is the %%f line>>myfile.txt)
echo.>>myfile.txt
echo.>>myfile.txt
::
:: Count the lines
for /f %%n in ('find /c /v "" ^< myfile.txt') do set lineCount1=%%n
echo There are %lineCount1% lines in myfile.txt
::
for /f "delims=:" %%n in ('findstr /n "^.*$" myfile.txt') do (
set lineCount2=%%n)
echo There are %lineCount2% lines in myfile.txt
::
:: Clean up
for %%f in (myfile.txt) do if exist %%f del %%f
endlocal & goto :EOF
The output will be
C:\_D\TEST>cmdfaq
There are 9 lines in myfile.txt
There are 10 lines in myfile.txt
The first method may produce a faulty results.
and
References/Comments:
http://www.google.com/groups?selm=1rzseucveq575$.53nvvmu63px4.dlg%4040tude.net