home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / programm / 4035 < prev    next >
Encoding:
Text File  |  1992-07-31  |  1.3 KB  |  42 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!wupost!monsanto.com!skws02!bcschu
  3. From: bcschu@skws02.monsanto.com (Brett Schultz)
  4. Subject: Re: Better way to find out the number of lines in a file
  5. Message-ID: <1992Jul31.124507.15622@tin.monsanto.com>
  6. Sender: news@tin.monsanto.com (USENET News System)
  7. Organization: Monsanto Company
  8. References: <1254@uknet.ac.uk>
  9. Date: Fri, 31 Jul 1992 12:45:07 GMT
  10. Lines: 30
  11.  
  12. tlg@uknet.ac.uk (Tim.Goodwin) writes:
  13. : In article <5412@ucsbcsl.ucsb.edu> 6500mack@ucsbuxa.ucsb.edu (Michael P. Mack) writes:
  14. : >Somebody has done it.  On our system (HPUX 8.0) we have a command
  15. : >called 'wc' which counts the lines, words, and characters in a file.
  16. : If you're only interested in the number of lines,
  17. :     grep -c '^'
  18. : is, on my system at least, much faster than
  19. :     wc -l
  20. : (That's GNU grep, of course.  It even seems to go faster than a naive
  21. I was thinking of the way to count from a C program.  I was just thinking
  22. there may be some sort of trick (via some system call or something) to do
  23. this other than using something like:
  24.  
  25.   system("wc -l file > tmp");
  26.  
  27.   Then read the number from the tmp file.
  28.  
  29. I guess the best way (from a C program with out using the above) would be
  30. to read the file into a buffer using fread and then count the number of 
  31. newline chars.
  32.  
  33.  
  34. Thanks for everyone's input
  35.  
  36. --Brett
  37.