Board logo

标题: 【求助】错在哪里? [打印本页]

作者: cat     时间: 2008-4-19 22:45    标题: 【求助】错在哪里?

我想在文件的每行开头加个序号,写了下面代码,不对。不知道错在哪里?
set/a count=0
for /f "delims=" %%i in (%1.txt)  do (   
       set /a count=count+1  
       echo %count%.%%i>>%1.txt
)

[ Last edited by cat on 2008-4-19 at 11:25 PM ]
作者: abcd     时间: 2008-4-19 22:49
call,echo %%count%%.%%i>>%1.txt
作者: ThinKing     时间: 2008-4-19 23:16
set/a=0

是什么意思?
作者: bat-zw     时间: 2008-4-19 23:48    标题: 这样好点吧:

这样不会丢失空行,如a.txt
@echo off
for /f "delims=: tokens=1*" %%i in ('findstr /n .* a.txt') do echo %%i.%%j>>b.txt
del /q a.txt&ren b.txt a.txt
start a.txt
[ Last edited by zw19750516 on 2008-4-20 at 12:00 AM ]
作者: cat     时间: 2008-4-19 23:59
非常感谢!!能解释一下'findstr /n .* 1.txt' ?

[ Last edited by cat on 2008-4-20 at 12:00 AM ]
作者: bat-zw     时间: 2008-4-20 00:04    标题: 可以:

findstr /n .* 1.txt的意思是对1.txt逐行逐字符处理"."是通配符指任何字符,"*"指重复,即同样的字符出现0或0次以上。
作者: moniuming     时间: 2008-4-20 00:12


  Quote:
Originally posted by zw19750516 at 2008-4-19 23:48:
这样不会丢失空行,如a.txt
[code]@echo off
for /f "delims=: tokens=1*" %%i in ('findstr /n .* a.txt') do echo %%i.%%j>>b.txt
del /q a.txt&ren b.txt a.txt
start a.tx ...

如果是批处理文件,那么标签前的两个点就会没了