On 02.02.2012 12:20 foxidrive wrote:
>>> for /f "tokens=1 delims=:" %%a in ('
>>> findstr /n /c:"END_OF_DATA" file.txt
>>> ') do set end=%%a
>> script operations will skip the empty lines. Thus in some cases, if one
>> uses the FINDSTR-generated information in the actual production batch,
>> the results might be out of synch.
> As we often do, the code answers what was asked for, not what *might* be required.
Just for the sake of the exercise:
What to do if one for some reason needs to ignore the empty lines. It
gets more complicated, but still is doable. Let's, however, only
consider the END_OF_DATA for brevity.
@echo off & setlocal enableextensions enabledelayedexpansion
set filename_=C:\_D\TEST\My test file.txt
set linecount_=
for /f "usebackq tokens=1 delims=:" %%a in (
`type "%filename_%"`) do (
set /a lineCount=!lineCount!+1
echo "%%a"|find "END_OF_DATA">nul
if !errorlevel! EQU 0 set endDataNR_=!lineCount!)
echo lineCount=%lineCount% endDataNR_=%endDataNR_%
endlocal & goto :EOF
More e.g. in
http://www.netikka.net/tsneti/info/tscmd064.htm