Computing.Net > Forums > Disk Operating System > Count line in a text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Count line in a text file

Reply to Message Icon

Name: smilaou
Date: October 3, 2003 at 06:02:30 Pacific
OS: win 2000
CPU/Ram: Atlon XP 1600+/ 512
Comment:

Hi every body
I need to count the number of line in a file. My file is like this:
|tetrte|ezrzer|||||erez|
|tetrte|ezrzer|||||erez|
|tetrte|ezrzer|||||erez|

I found something: find /C "|" filename
I am a newbie in Dos so don't manage to get the result number in a single variable.
Set toto = find /C "|" filename...

Thx for help,
Smilaou



Sponsored Link
Ads by Google

Response Number 1
Name: smilaou
Date: October 3, 2003 at 06:36:21 Pacific
Reply:

I see that i can redirect the count in a file but on the same line i need to write a message:
echo fin 'The count' > filename

this don't work :(


0

Response Number 2
Name: dualpurpose
Date: October 3, 2003 at 19:08:26 Pacific
Reply:

Hi smilaou...

I think this is what you need... try it!

echo e100'set %%1='> %temp%.\temp.bat
for %%? in (rcx 7 w q) do echo %%?>> %temp%.\temp.bat
type %temp%.\temp.bat |DEBUG %temp%.\temp.bat > nul

rem Find the count in (somefile.ext)

find /c "|" < somefile.ext >> %temp%.\temp.bat

rem: sets result of FIND to the variable "number"

call %temp%.\temp.bat number
del %temp%.\temp.bat

echo Finished The count is %number% > result.ext

set number=

:eof

result.ext would have one line as this " Finished The count is 5" for example

dual


0

Response Number 3
Name: Rambler
Date: October 4, 2003 at 10:25:30 Pacific
Reply:

A rather simpler one-liner can be found here:

http://discussions.virtualdr.com/showthread.php?s=&threadid=146504


0

Response Number 4
Name: dualpurpose
Date: October 4, 2003 at 10:54:29 Pacific
Reply:

Thats a good one Rambler

However it's not clear if the file would contain other unknown characters not specified in /V
if so the count would be inacurate, also no %variable% is set and no echo of the desired line to a file

Just a thought? im learning here too

Dual


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Count line in a text file

+/- 1 line from a text file. www.computing.net/answers/dos/-1-line-from-a-text-file/14211.html

store processing result in a text file www.computing.net/answers/dos/store-processing-result-in-a-text-file/7409.html

copying files listed in a text file www.computing.net/answers/dos/copying-files-listed-in-a-text-file/7341.html