I have a file where some lines consist of whitespaces only. I need to skip those lines and only display lines that are not whitespaces.
Say, the file looks like this:
Beginnng of file. Middle of file. This is next to end line of file. This is end of file.
I have the following batch script:
@ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION FOR /F "usebackq delims=" %%a in ("file.txt") DO ( ECHO.%%a | findstr "^[\t ]*$" IF errorlevel=1 ECHO.%%a ) SETLOCAL DISABLEDELAYEDEXPANSION
I am expecting to see the following result:
Beginning of file. Middle of file. This is next to end line of file. This is end of file.
However it’s not working. My regular expression is incorrect. Please help me fix it.
-Greg.
this should work:
findstr /r “[^\ ]” test.txt
for what you want, but the command totally bombs.
and a for-example (just test for space at beg. of line)
findstr /r “^\ “
should work. Instead it bitches that there are no strings supplied.
It works for some things, but sucks for others (mostly,
apparently, involving spaces.)
you could work around it:
for /f %%a in (file) do (
set test=%%a
set test=!test: =!
if “!test!” neq “” >> newfile echo %%a
)
::—- end
It’s not your fault, this one’s squarely in MS’s jurisdiction
AFAIC, putting out sucky commands.