如何通过bat批处理去掉一个文本文件中的<>符号及其中的内容?

2025-02-27 13:21:00
推荐回答(3个)
回答1:

批处理命令里>是命令语句之一,不可以当成文字用。BAT无法完成。真的要删除另有方法,打开你的文件后,按下键盘CTRL+H ,调出替换功能就可以搞定了。把你要删除的东西替换成无数据就可以了。用WORD替换功能更强大好用,速度也快多了。

回答2:

兄弟··楼上那个说的很对,你真想去掉它们就直接用记事本打开,然后查找<和>符号,然后批量替换就可以了,你何必把自己弄的那么累呢,有时候简单的东西是最好的~~~

回答3:

The following codes may help you in some way. But strongly recommend you choose VBS regular expression to do the job. It will be much quicker and more universal.

@ECHO OFF
IF NOT EXIST "%~1" GOTO :EOF
ECHO 请稍后. . .
SET newName="%~dpn1_uu%~x1"
SETLOCAL EnableDelayedExpansion
(FOR /F "usebackq delims=" %%I IN ("%~1") DO (
SET "U=%%I"
CALL :UU U
ECHO.!U!))>%newName%
START "" %newName%
GOTO :EOF

:UU
SET /A L=0 & SET "UT=!%1!" & SET "%1="
:U_N
IF NOT DEFINED UT GOTO :EOF
SET "B=!UT:~0,1!"
IF "!B!"=="<" (SET /A L+=1) ELSE (
IF "!B!"==">" (SET /A L-=1) ELSE (
IF %L% EQU 0 SET "%1=!%1!!B!"))
IF %L% LSS 0 (SET /A L=0 & SET "%1=!%1!>")
SET "UT=!UT:~1!"
GOTO :U_N
REM --------END--------

Save above codes into a batch file, e.g. "uu.cmd", which can be put in any folder. DRAG any text file onto the icon of "uu.cmd", then you will see the result. Please Hi me if any problem.