JSI Tip 7426. How do I strip blank and null lines from a file if it can contain CMD control characters?


In tip 7425, I scripted StripBN.bat to strip blank and null lines from a file that did not contain CMD control characters.

Using ReadIn, I have scripted StripBNC.bat to strip blank and null lines from a file that may contain CMD control characters.

The syntax for using StripBNC.bat is:

StripBNC FileName

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

StripBNC.bat contains:

@echo off
If \{%1\}==\{\} @echo Syntax Call StripBNC FileName&goto :EOF
if not exist %1 @echo StripBNC %1 not found.&goto :EOF
setlocal
set file=%1
if exist %TEMP%\StripBNC.tmp del /q %TEMP%\StripBNC.tmp
for /f "Tokens=*" %%i in ('ReadIN /f=%file% /c') do set line=%%i&call :parse1
ReadIn /F=%TEMP%\StripBNC.tmp /A /o=%file%
if exist %TEMP%\StripBNC.tmp del /q %TEMP%\StripBNC.tmp
endlocal
goto :EOF
:parse1
set work=%line: =%
if "%work%" EQU "" goto :EOF
@echo %line%>>%TEMP%\StripBNC.tmp



Hide comments

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.
Publish