我需要删除“|”来自.txt文件。 它应该是^ |在:
@echo off
setlocal enabledelayedexpansion
set INTEXTFILE=buffer.txt
set OUTTEXTFILE=test_out.txt
set SEARCHTEXT=^|
set REPLACETEXT=
set OUTPUTLINE=
for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
SET string=%%A
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!
echo !modified! >> %OUTTEXTFILE%
)
del %INTEXTFILE%
rename %OUTTEXTFILE% %INTEXTFILE%
但它不起作用 目前的答案是:string:
我也试过“|”和\ |
答案 0 :(得分:0)
此处需要引号,以避免解析器尝试处理管道符。
@echo off
setlocal enabledelayedexpansion
set INTEXTFILE=buffer.txt
set OUTTEXTFILE=test_out.txt
set "SEARCHTEXT=|"
set "REPLACETEXT="
set OUTPUTLINE=
for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
SET "string=%%A"
SET "modified=!string:%SEARCHTEXT%=%REPLACETEXT%!"
echo(!modified!
) > %OUTTEXTFILE%
del %INTEXTFILE%
rename %OUTTEXTFILE% %INTEXTFILE%