Board logo

标题: 如何用批处理将以下内容写入a.txt [打印本页]

作者: pinghu     时间: 2008-2-6 01:21    标题: 如何用批处理将以下内容写入a.txt

set num=0
setlocal enabledelayedexpansion
for /f "delims=" %%i in (input.txt) do call :intercept "%%i"
echo value=%str_%
pause
goto :eof

:intercept
set str=%1
set str=%str:~2,-2%
if not "%str%"=="" echo. "%str:~0,1%"|findstr "[0-9]">nul && (
    set num=1&set str_=!str_!%str:~0,1%&&call :intercept " !str:~1! ")||(
    if %num% equ 0 call :intercept " !str:~1! "
)
goto :eof
作者: terse     时间: 2008-2-6 01:31
more +1 %0>aaaa.txt &&exit
set num=0
setlocal enabledelayedexpansion
for /f "delims=" %%i in (input.txt) do call :intercept "%%i"
echo value=%str_%
pause
goto :eof

:intercept
set str=%1
set str=%str:~2,-2%
if not "%str%"=="" echo. "%str:~0,1%"|findstr "[0-9]">nul && (
    set num=1&set str_=!str_!%str:~0,1%&&call :intercept " !str:~1! ")||(
    if %num% equ 0 call :intercept " !str:~1! "
)
goto :eof
作者: pinghu     时间: 2008-2-6 11:36
我的本意是问一问
每一行都用echo的形式怎么输出。这个more的用法我赚到了!!
作者: pinghu     时间: 2008-2-6 11:59
我这个批处理后面还有其他命令呢 ,用2楼的方法不是把批处理自身的命令也写进txt里面了?
作者: slore     时间: 2008-2-6 12:20
你改成+5看看效果
作者: pinghu     时间: 2008-2-6 15:19
+5的方法我试了,还是取到文件末尾啊
我不想取道文件末尾,只想截取一个批处理文件中间的几行,用这个命令还行吗
作者: pinghu     时间: 2008-2-6 15:39
用echo语句一行一行的写上述bat命令如何实现
作者: pinghu     时间: 2008-2-6 15:46
我如果写echo set num=0就会输入为空我要是写echo “set num=0”就会多出双引号
要把命令写进文本就那么难吗
作者: slore     时间: 2008-2-6 16:17
echo set num=0 >a.txt
作者: pinghu     时间: 2008-2-6 16:38    标题: 在slore的提示下我终于搞定了

echo set num=0 > a.txt
echo setlocal enabledelayedexpansion >> a.txt
echo for /f "delims=" %%%%i in (input.txt) do call :intercept "%%%%i" >> a.txt
echo echo value=%%str_%% >> a.txt
echo pause >> a.txt
echo goto :eof >> a.txt
echo. >> a.txt
echo :intercept >> a.txt
echo set str=%%1 >> a.txt
echo set str=%%str:~2,-2%% >> a.txt
echo if not "%%str%%"=="" echo. "%%str:~0,1%%"^|findstr "[0-9]"^>nul ^&^& ( >>a.txt
echo     set num=1^&set str_=!str_!%%str:~0,1%%^&^&call :intercept " !str:~1! ")^|^|( >>a.txt
echo     if %%num%% equ 0 call :intercept " !str:~1! " >> a.txt
echo ) >> a.txt
echo goto :eof >> a.txt
作者: pinghu     时间: 2008-2-6 17:36
我总结的经验是><|&用^>^<^|^&来替换,%用%%来替换
作者: erick456     时间: 2008-2-6 17:52
顶下人气
作者: zlp1982994     时间: 2008-2-8 17:10
学到了!
作者: pinghu     时间: 2008-2-9 15:49    标题: 发现一个问题

echo set num=0 >a.txt 执行的结果:set num=0的后面有一个空格这会影响数据的使用,解决办法:
(echo set num=0)>a.txt