如何用批处理删除文本文件第一行前面4个数字 批处理

2025-04-06 21:23:26
推荐回答(3个)
回答1:

@echo off&setlocal enabledelayedexpansion&pushd %~dps0
for /f "delims=" %%1 in ('type %1')do (set/a a+=1
if "!a!"=="1" (set a=%%1&set a=!a:~4,-1!!a:~-1!&echo !a!>>"%~fn1.tmp")else echo %%1>>"%~fn1.tmp")
move "%~fn1.tmp" "%~nx1"
::将需要处理的文件拖到批处理图标上

回答2:

::设原文件为test.txt,改后文件为temp.txt
@echo off
for /f "delims=" %%a in (test.txt) do (
set str=%%a
echo.%str:~4%>temp.txt
goto :next
)
:next
more +1 test.txt>>temp.txt
start temp.txt

回答3:

假设是a.txt
@echo off
set /p Str=Echo %Str:~4%>a.txt_
More +1>a.txt_
del a.txt
ren a.txt_ a.txt