Reputation:
I have a small batch file to search and replace within a batch file. I am having difficulty removing things (eg replacing some text with a null value). Am sure it is simple but not found anything by searching!
This is the file:
Where you see xxxxx and yyyyy is where I need a blank!
Cheers.
@echo off
setlocal enabledelayedexpansion
if exist %~n1.bugs%~x1 del %~n1.bugs%~x1
if not exist "%1" (echo this file does not exist...)&goto :eof
set FIND_LOGO_1_DATA=logo_data_0 101
set FIND_LOGO_2_DATA=logo_data_0 102
set FIND_LOGO_3_DATA=logo_data_0 103
set FIND_LOGO_4_DATA=logo_data_0 104
set FIND_LOGO_5_DATA=logo_data_0 107
set FIND_LOGO_6_DATA=logo_data_0 108
set FIND_LOGO_7_DATA=logo_data_0 109
set FIND_LOGO_8_DATA=logo_data_0 110
set FIND_LOGO_9_DATA=logo_data_0 105
set FIND_LOGO_10_DATA=logo_data_0 106
for /f "tokens=* delims=" %%a in (%1) do (
set write=%%a
if "%%a"=="logo_0 2" set write=xxxxx
if "%%a"=="logo_0 1" set write=yyyyy
if "%%a"=="%FIND_LOGO_1_DATA%" set write=logo_0 1
if "%%a"=="%FIND_LOGO_2_DATA%" set write=logo_1 1
if "%%a"=="%FIND_LOGO_3_DATA%" set write=logo_2 1
if "%%a"=="%FIND_LOGO_4_DATA%" set write=logo_3 1
if "%%a"=="%FIND_LOGO_5_DATA%" set write=logo_4 1
if "%%a"=="%FIND_LOGO_6_DATA%" set write=logo_5 1
if "%%a"=="%FIND_LOGO_7_DATA%" set write=logo_6 1
if "%%a"=="%FIND_LOGO_8_DATA%" set write=logo_7 1
if "%%a"=="%FIND_LOGO_9_DATA%" set write=logo_8 1
if "%%a"=="%FIND_LOGO_10_DATA%" set write=logo_9 1
(echo !write!)>>%~n1.bugs%~x1
)
Upvotes: 0
Views: 664
Reputation: 354496
If I'm seeing this correctly, then you just want to output a blank line in the two cases where you currently have xxxxx
and yyyyy
, right?
If that's the case, then it's actually very easy. You just have to set write
to nothing:
set write=
and alter the line where you echo
that variable in the following way:
echo.!write!
This will cause echo to output an empty line if write
is empty and suppress the "ECHO is off." message (also documented here).
Upvotes: 1