Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
Credits 4,103 Posts 1,744 Joined 2006-01-20 13:00 20-year member UID 49241 Gender Male From 甘肃.临泽
Status Offline
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.
Credits 1,187 Posts 555 Joined 2006-12-21 07:35 19-year member UID 74129 Gender Male
Status Offline
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?
Credits 493 Posts 228 Joined 2007-02-16 00:38 19-year member UID 79596 Gender Male From 安徽
Status Offline
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 ]
Credits 19 Posts 5 Joined 2007-10-10 15:51 18-year member UID 99367 Gender Male
Status Offline
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>