Re: ? Number of lines in a file [message #8138 is a reply to message #8014] |
Thu, 06 February 1997 00:00  |
Karlheinz Knipp
Messages: 2 Registered: November 1996
|
Junior Member |
|
|
David Kennedy wrote:
>
> 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.
> --
> David Kennedy, Dept. of Pure & Applied Physics, Queen's University of Belfast
> Email: D.Kennedy@Queens-Belfast.ac.uk | URL: http://star.pst.qub.ac.uk/~dcjk/
> Hi! I'm a .signature virus! Copy me into yours and join the fun!
1. Under UNIX it's also possible to use: awk "END {print NR}"
but again: it's a system-call
2. How about the following:
;
------------------------------------------------------------ ------------------
; open file, get number of bytes, associate data
openr, uni, input_file, /get_lun & point_lun, uni, 0
stat = fstat(uni)
bytes = stat.size
if bytes eq 0 then begin
free_lun, uni
return, 0
endif
i = assoc(uni, bytarr(bytes))
;
------------------------------------------------------------ ------------------
; count
test = where(i(0) eq 10b)
if test(0) eq -1 then count = 0 else count = n_elements(test)
;
------------------------------------------------------------ ------------------
; free file, return & end
free_lun, uni
return, count
end
Have fun,
Karl
--
Karlheinz Knipp knipp@digitalmap.hi.bosch.de
Robert Bosch Data GmbH Dep. DG-PMM
Robert Bosch Str. 200 D-31139 Hildesheim
Tel.: +49 5121 49 5406 Fax.: +49 5121 49 4815
|
|
|