I have .txt files with thousand of records. Records contain numbers only (upto 9 characters long+CR+LF). There might be some empty lines - and these cause problems.
I have many .txt files:
a.txt
b.txt
c.txt
etc...
For example a.txt:
Code: Select all
34095142
34095143
34095144
34095212
34095145
34095146
34095578
34095581
34095202
34094740
34103146
34095167
and now the code:
Code: Select all
@echo off
set /a cnt=0
for /f "tokens=2 delims=:" %%f in ('find /V /C "" *.txt') do set /a cnt=cnt + %%f
echo find_count: %cnt%
set /a cnt=0
for /f "tokens=1" %%f in (a.txt) do set /a cnt=cnt+1
echo for/f count: %cnt%
I use first command (find /v /c...) to get the numbers of records.
Then I process each file and count the records (and do other things). As you can see (and we all know) that FOR /F skips empty lines so the total number of records is not the same.
Code: Select all
c:\a.cmd
find_count: 16
for/f count: 12
c:\
Any other solution to get the correct number of records with the FIND command (without empty lines)? At the end I can replace the code with the FOR /F counting.
Thanks.
Saso