Show me a histogram of the busiest minutes in a log file:

cat /var/log/secure.log | awk '{print substr($0,0,12)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'
Busiest seconds: cat /var/log/secure.log | awk '{print substr($0,0,15)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'
Sample Output
-macbook:~ root# cat /var/log/secure.log | awk '{print substr($0,0,12)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}' | head

   9 Jul 21 20:21 *********
   9 Jul 20 19:46 *********
   9 Jul 20 14:46 *********
   7 Jul 23 16:55 *******
   6 Jul 22 21:01 ******
   6 Jul 20 21:05 ******
   5 Jul 22 21:02 *****
   4 Jul 20 21:25 ****
   4 Jul 20 21:12 ****

17
By: knassery
2009-07-24 07:20:06

What Others Think

Nicely done!! I would remove cat to make it a little more efficient: awk '{print substr($0,0,15)}' /var/log/secure.log | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'
zlemini · 485 weeks and 5 days ago
I would replace the first awk with: cut -c1-12
ger · 485 weeks and 1 day ago
Love it. Thanks. To check my log4j files for the current hour I tweaked to: grep "^$(date '+%Y-%m-%d %H')" /blah/blah/logs/someLog4j.log | awk '{print substr($0,0,17)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}';echo
mccalni · 485 weeks ago
Fantastic! Great little tool.
Vilemirth · 300 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: