JSI Tip 7425. How do I strip blank and null lines from a file?

I have scripted StripBN.bat to strip blank and null lines from a file.

The syntax for using StripBN.bat is:

StripBN FileName

NOTE: StripBN.bat will also remove leading spaces on each line.

NOTE: If FileName can contain CMD control characters, as in a HTML file, use StripBNC.bat.

StripBN.bat contains:

@echo off
If \{%1\}==\{\} @echo Syntax Call StripBN FileName&goto :EOF
if not exist %1 @echo StripBN %1 not found.&goto :EOF
set file=%1
copy %file% %TEMP%\StripBN.tmp
del /q %file%
for /f "Tokens=*" %%i in (%TEMP%\StripBN.tmp) do if \{%%i\} NEQ \{\} @echo %%i>>%file%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.