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