this blog is girtby.net

Posted
14 February 2005

Categories
Nerd Factor X

Tags

3 Comments

Another Unix Tip

How to count the instances of a given character in a file? grep -c won’t do it - instead it counts the number of maching lines. You need:

cat foo.c | tr -c -d ';' | wc -c

Which counts all the semicolons in foo.c. (source)

Unix - it’s the OS that won’t cop out when there’s text all about! (source)

3 Comments

Posted by
Alan Green
2005-02-14 12:10:15 -0600
#

Hmmm… semicolons. Are you sure you don’t want SLOCCount instead?

http://www.dwheeler.com/sloccount/sloccount.html

:)


Posted by
Alastair
2005-02-14 12:10:15 -0600
#

The example given was purely hypothetical and bears no resemblance to idiotic management requests for coding metrics, living or dead.

You believe me, right? :)


Posted by
Nevets
2005-02-14 12:10:15 -0600
#

This works, I actually had a business requirement to count the instances of a '$' in a file. Go figure.