DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Albert has posted 3 posts at DZone. View Full User Profile

Faster Line Count With Grep Rather Than Wc

08.04.2010
| 14641 views |
  • submit to reddit
        wc can be dramatically slower than desirable if all you want is a count of lines in a file (e.g., ~6 minutes vs. the grep technique shown below, which took 10 seconds).

grep -c '\n' filename