Help us understand the problem. What is going on with this article?

コマンドライン上でヒストグラム値(頻度数)を求める

More than 3 years have passed since last update.

こんにちは。
コマンドライン上でヒストグラム値(頻度数)を求めてみました1。処理例は history コマンドの第2カラムです(すなわち過去に使用したコマンド名)。

$ history | awk '{print $2}' | ./hist.sh | ./hist_graph.sh
            brew   87 ##################################################
             pip   33 ###################
              ls   30 #################
               :
               :
  • 頻度数を求める処理部分は:
hist.sh
#!/bin/sh
cat "$@" | sort | uniq -c | sort -k1nr | awk '{printf "%16s %4d\n",$2,$1;}'
exit 0
  • 図示(#の連続)を付け加える処理部分は:
hist_graph.sh
#!/bin/sh
cat "$@" | awk '!max{max=$2;}{f=50/max;if(f>1)f=1;i=$2*f;r="";while(i-->0)r=r"#";printf "%s %s\n",$0,r;}'
exit 0

なお改めてヒストグラム実現方法を調べてみると、"in-terminal (ASCII) histograms tool" (Stack Overflow) の中で、下記も紹介されていました。
* https://github.com/bitly/data_hacks
* https://github.com/philovivero/distribution



  1. ただしこの話題は「CSVデータのヒストグラム値(頻度数)の計算(qコマンド利用)」とほとんど同じなので恐縮です。 

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away