comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » ? Number of lines in a file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: ? Number of lines in a file [message #8137 is a reply to message #8014] Thu, 06 February 1997 00:00 Go to previous messageGo to previous message
derekfox is currently offline  derekfox
Messages: 1
Registered: February 1997
Junior Member
In article <1997Feb5.160127.7541@queens-belfast.ac.uk>, D.Kennedy@qub.ac.uk (David Kennedy) writes:
> In article <5ctkah$rqq@uwm.edu>,
> gunter@alpha1.csd.uwm.edu (David Gunter) writes:
>> I need to know how many lines are in a file so I use:
>>
>> spawn, "fgrep -cv 'gbrsh' "+filename, n_lines
>>
>> Is there a more efficient way to do this? I've searched the manuals with no
>> luck.
>>
>> BTW, I'm running on a UNIX system for those confused by the above line. ;)
>
> Well, this isn't much easier but 'wc -l'(UNIX) returns the number of lines
> in a file, it simplifies things if nothing else.
> --

If you're willing to have another one-trick pony sitting in your
$IDL_PATH, using IDL-only routines will be much faster (factor of 50
improvement on my machine), after compilation, than any "spawn".

Try this "n_lines.pro".

One warning: results seem to differ form those of `wc -l` for non-ascii
files.

--Derek Fox


function n_lines,file

on_ioerror,ioerr
openr,unit,file,/get_lun,error=err
if err ne 0 then begin
ioerr:
message,'Error reading file '+file,/inform
return,-1
endif

nlines=0l & line=''
while not eof(unit) do begin
readf,unit,line
nlines=nlines+1
endwhile
free_lun,unit

return,nlines
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: 32-bit Unsigned Integers, Was: Unsigned Integers - How?
Next Topic: Re: help command

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:18:16 PDT 2025

Total time taken to generate the page: 0.00816 seconds