批量删除|来自txt文件

时间:2014-08-19 09:44:46

标签: batch-file pipe text-files

我需要删除“|”来自.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:

我也试过“|”和\ |

1 个答案:

答案 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%