|
不知楼主是不是要在第二行和倒数第二行插入新的一行(内容123)。如果是,下面的代码不妨一试(假设要修改的文件c:\abc.txt):
-----------------------------分割线--------------------------------
@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:\tmp.txt
if !aa!==1 echo 123 >>c:\tmp.txt
if !n!==1 echo 123 >>c:\tmp.txt
)
del /q c:\abc.txt
ren c:\tmp.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:\tmp.txt) else echo %%a >>c:\tmp.txt
)
for /f "delims=" %%a in (c:\tmp.txt) do set /a n=!n!+1
for /f "delims=" %%a in (c:\tmp.txt) do (
set /a n=!n!-1
if !n!==1 (echo 123%%a >>c:\tmp1.txt) else echo %%a >>c:\tmp1.txt
)
del /q c:\abc.txt
del /q c:\tmp.txt
ren c:\tmp1.txt abc.txt
pause
-----------------------------分割线--------------------------------
[ 本帖最后由 2011pzn 于 2011-11-10 13:48 编辑 ] |
|