|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
|
2007-2-26 09:07 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
for /f "delims=" %%i in (l.txt) do (set/a num+=1)
echo len=%num%
但是以行中若是回车符号,结果就不对,怎么改,谢谢!
for /f "delims=" %%i in (l.txt) do (set/a num+=1)
echo len=%num%
But if there are carriage return symbols in the line, the result will be incorrect. How to modify it, thanks!
|
|
2007-2-26 09:31 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
看你要不要空行和开头是;的行了
See if you need blank lines and lines starting with ;
|
|
2007-2-26 09:48 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
都要
只要一行中有字符,不管是什么字符
包括只有一个回车符号的行
Last edited by scriptor on 2007-2-25 at 09:42 PM ]
All need. As long as there are characters in a line, no matter what characters they are. Including lines with only one carriage return character.
Last edited by scriptor on 2007-2-25 at 09:42 PM ]
|
|
2007-2-26 09:57 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by scriptor at 2007-2-26 09:57:
都要
只要一行中有字符,不管是什么字符
包括只有一个回车符号的行
Last edited by scriptor on 2007-2-25 at 09:42 PM ]
那还是用sed好了 sed -n $= life
因为当文件中有空行时用findstr /N . life还是会忽略空行的
Originally posted by scriptor at 2007-2-26 09:57:
All are required. As long as there are characters in a line, no matter what characters they are. Including lines with only a carriage return character.
Last edited by scriptor on 2007-2-25 at 09:42 PM ]
Then still use sed. sed -n $= life. Because when there are blank lines in the file, using findstr /N . life will still ignore blank lines.
|
|
2007-2-26 11:00 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
我的l.txt的内容是:
w
e
我的bat文件是:
@echo off
for /f "delims=" %%i in ('find /v /i /n "" l.txt') do (set/a num+=1)
echo len=%num%
pause>nul
结果为4,但是只有三行啊??
难道要这样减去1才对?这是什么道理?
还有别的方法不?
The content of my l.txt is:
w
e
The content of my bat file is:
@echo off
for /f "delims=" %%i in ('find /v /i /n "" l.txt') do (set/a num+=1)
echo len=%num%
pause>nul
The result is 4, but there are only three lines??
Does it have to be subtracted by 1 like this to be correct? What's the reason for this?
Are there other methods?
|
|
2007-2-26 11:23 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
|
2007-2-26 11:45 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
你是说用vbs或js?
那个当然可以。可是我要的是bat的
You mean using VBS or JS?
Of course that's possible. But what I want is bat.
|
|
2007-2-26 11:53 |
|
|
xycoordinate
中级用户
  
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal enabledelayedexpansion
set i=0
for /f %%a in (1.txt) do (
set /a i+=1
echo !i! %%a >>1new.txt
)
不能包括空行!<img src="images/smilies/face-sad.png" align="absmiddle" border="0">
Last edited by xycoordinate on 2007-2-26 at 10:10 AM ]
@echo off
setlocal enabledelayedexpansion
set i=0
for /f %%a in (1.txt) do (
set /a i+=1
echo !i! %%a >>1new.txt
)
Cannot include blank lines! :(
Last edited by xycoordinate on 2007-2-26 at 10:10 AM ]
|
|
2007-2-26 23:07 |
|
|
qjbm
初级用户
 
积分 125
发帖 44
注册 2007-1-24
状态 离线
|
 『第 10 楼』:
使用 LLM 解释/回答一下
scriptor兄
给你个变态方法!!哈哈利用一下SET /A的小BUG
@ECHO %DBG% OFF & SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F %%i IN ('findstr /n . l.txt') DO SET /A LEN=%%i 2>nul
ECHO %LEN%
Brother Scriptor,
Here's a weird method!! Haha, take advantage of a small bug in SET /A.
@ECHO %DBG% OFF & SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F %%i IN ('findstr /n . l.txt') DO SET /A LEN=%%i 2>nul
ECHO %LEN%
|
|
2007-2-26 23:52 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
   『第 11 楼』:
使用 LLM 解释/回答一下
可以处理空行及包含其它字符的行:@echo off
for /f "tokens=1 delims=:" %%a in ('findstr /n .* 1.txt') do set a=%%a
echo The length of file 1.txt is %a%
pause&exit/b0
It can handle blank lines and lines containing other characters:
@echo off
for /f "tokens=1 delims=:" %%a in ('findstr /n .* 1.txt') do set a=%%a
echo The length of file 1.txt is %a%
pause&exit/b0
|
|
2007-2-27 00:01 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
10 楼的效果和:
@echo off
FOR /F "delims=:" %%i IN ('findstr /n . a.txt') DO SET LEN=%%i
ECHO %LEN%
pause
是一样的,利用了set/a去除了数字后面的“:”字符
SET LEN=%%i:设置LEN等于findstr /n显示的行数(不用计数),包含所有行
Last edited by zh159 on 2007-2-26 at 11:04 AM ]
The effect of floor 10 is the same as:
@echo off
FOR /F "delims=:" %%i IN ('findstr /n . a.txt') DO SET LEN=%%i
ECHO %LEN%
pause
It uses set/a to remove the ":" character after the number.
SET LEN=%%i: Set LEN equal to the number of lines displayed by findstr /n (no need to count), including all lines
Last edited by zh159 on 2007-2-26 at 11:04 AM ]
|
|
2007-2-27 00:02 |
|
|
xycoordinate
中级用户
  
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by zh159 at 2007-2-27 00:02:
10 楼的效果和:
@echo off
FOR /F "delims=:" %%i IN ('findstr /n . a.txt') DO SET LEN=%%i
ECHO %LEN%
pause
是一样的,利用了set/a去除了数字后面的“:”字符
SET LEN=%%i:设置LEN等于findstr /n显示的行数(不用计数),包含所有行
10楼的,主要是用了 2>nul,妙!!!
Last edited by xycoordinate on 2007-5-5 at 10:49 AM ]
Originally posted by zh159 at 2007-2-27 00:02:
The effect of floor 10 is the same as:
@echo off
FOR /F "delims=:" %%i IN ('findstr /n . a.txt') DO SET LEN=%%i
ECHO %LEN%
pause
It uses set/a to remove the ":" character after the number.
SET LEN=%%i: Set LEN equal to the number of lines displayed by findstr /n (without counting), including all lines
For floor 10, mainly used 2>nul, wonderful!!!
Last edited by xycoordinate on 2007-5-5 at 10:49 AM ]
|
|
2007-5-5 10:47 |
|
|
hizebra
新手上路

积分 19
发帖 5
注册 2007-10-10
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
look!
<a href="http://www.cn-dos.net/forum/viewthread.php?tid=33878&fpage=1&highlight=%E8%A1%8C%E6%95%B0" target="_blank">批处理中如何判断一个文本中的行数</a>
look!
<a href="http://www.cn-dos.net/forum/viewthread.php?tid=33878&fpage=1&highlight=%E8%A1%8C%E6%95%B0" target="_blank">How to determine the number of lines in a text in batch processing</a>
|
|
2007-12-24 01:10 |
|
|
ZJHJ
高级用户
   
积分 609
发帖 374
注册 2006-8-2
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
没明白?为什么速度比
find /v /c "" 1.txt>cs.txt
for /f "tokens=2 delims=:" %%i in (cs.txt) do @echo %%i
慢很很多呢??
Don't understand? Why is it much slower than
find /v /c "" 1.txt>cs.txt
for /f "tokens=2 delims=:" %%i in (cs.txt) do @echo %%i
|
|
2007-12-24 09:03 |
|