4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mysqlの特定のカラムを形態素解析して単語を頻出順でソートするワンライナー

4
Posted at

ワンライナー


# 全体
mysql -h 0.0.0.0 -u user -psecret dbname -Nse 'select column_name from table_name;' | docker run -i -a STDIN -a STDOUT tsutomu7/mecab | cut -f 1 | sort | uniq -c | sort -r -n

# 名詞だけ抽出
mysql -h 0.0.0.0 -u user -psecret dbname -Nse 'select column_name from table_name;' | docker run -i -a STDIN -a STDOUT tsutomu7/mecab | awk '(index($2,"名詞") != 0) {print $1}' | sort | uniq -c | sort -r -n

requirement

  • mysqlがローカルで立ち上がっている
  • dockerが入っている

解説

  1. mysql -Nseでインラインでmysqlのクエリを標準出力
  2. tsutomu7/mecabでmecabのコマンドを実行
  3. 必要な単語を抽出
  4. ソートし、 uniq -c で重複をカウント
  5. sort -r -n で数字で逆順出力
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?