Thursday, February 7, 2013

Count the number of text occurences in a file

Just another boring work note.  Sorry, not that entertaining.  But if you are on Linux, and want to the number of occurences of each word in a file, this rocks!

 awk 'NF{ count[ toupper( $0 ) ]++}
END{ for (name in count ) { print name " appears " count[ name ] " times" };
}' /tmp/companyname_services.log

In this instance, the input file was /tmp/companyname_services.log

No comments:

Post a Comment