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

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Count line in a text file

Reply to Message Icon

Original Message
Name: smilaou
Date: October 3, 2003 at 06:02:30 Pacific
Subject: Count line in a text file
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


Report Offensive Message For Removal


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

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 :(


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal

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

A rather simpler one-liner can be found here:

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


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal







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








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge
Poll History




Data Recovery Software