参考出处:http://bbs.wuyou.com/forum.php?mod=viewthread&tid=202142&page=1
第二行和倒数第二行插入新的一行(内容123)
-----------------------------分割线--------------------------------
@echo off
setlocal ENABLEDELAYEDEXPANSION
set n=0
set aa=0
for /f "delims=" %%a in (c:abc.txt) do set /a n=!n!+1
for /f "delims=" %%a in (c:abc.txt) do (
set /a aa=!aa!+1
set /a n=!n!-1
echo %%a >>c: mp.txt
if !aa!==1 echo 123 >>c: mp.txt
if !n!==1 echo 123 >>c: mp.txt
)
del /q c:abc.txt
ren c: mp.txt abc.txt
pause
-----------------------------分割线--------------------------------
如果只是添加123而不是插入新行,方法类似。比如在第二行和倒数第二行开头添加123:
-----------------------------分割线--------------------------------
@echo off
setlocal ENABLEDELAYEDEXPANSION
set n=0
set aa=0
for /f "delims=" %%a in (c:abc.txt) do (
set /a aa=!aa!+1
if !aa!==2 (echo 123%%a >>c: mp.txt) else echo %%a >>c: mp.txt
)
for /f "delims=" %%a in (c: mp.txt) do set /a n=!n!+1
for /f "delims=" %%a in (c: mp.txt) do (
set /a n=!n!-1
if !n!==1 (echo 123%%a >>c: mp1.txt) else echo %%a >>c: mp1.txt
)
del /q c:abc.txt
del /q c: mp.txt
ren c: mp1.txt abc.txt
pause
-----------------------------分割线--------------------------------