
The little snippet below outputs the number and contents of any lines found in a user-specified file that don’t contain a Line Feed. And then it does it again.
First using a bare findstr, and then using findstr wrapped inside a for /f loop’s in (…) clause.
Code: Select all
@echo off & setlocal enableextensions
set file="%~1"
(set lf=^
)
set nl=^^^%lf%%lf%^%lf%%lf%
echo(bare findstr
findstr /nv %nl% %file%
echo(%nl%%nl%findstr wrapped inside for /f loop's in (...^) clause
for /f "delims=" %%f in ('findstr /nv %%nl%% %file%') do echo(%%f
endlocal & exit /b 0
The bare findstr only requires %nl%, but inside the loop’s in (…) clause it is necessary to write %%nl%%. On the other hand, %file% works just fine in both cases.
What’s going on here? Can someone please explain?

- SB