qq コマンドは、標準出力をパイプで受け取ったあと、
テーブルとしてSQLでデータ操作が出来るコマンド。
何かしらの出力結果から、SQLでフィルタしたりと色々便利な使い方ができそう。
qq コマンドのインストール
goのインストールと、GOPATHが設定されているものとして、
以下のコマンドを実行して、qqコマンドをインストールする。
go-encodingに依存している為、こちらもインストールしておく。
# go get
go get github.com/mattn/qq
go get github.com/mattn/go-encoding
# binを作成して、PATHを通す。
cd $GOPATH/src/github.com/mattn/qq
go install ./cmd/qq
go install で、qqコマンドにPATHがとおる。
インストールされている事を確認
which qq
# ===> /Users/tyabuta/.go/bin/qq
Usage
qq -h
Usage of qq:
-e string
encoding of input stream
-ic
input csv
-il
input ltsv
-ip string
input delimiter pattern as regexp
-it
input tsv
-nh
don't treat first line as header
-oh
output header line
-oj
output json
-or
output raw
-q string
select query
つかってみる
psコマンドの出力結果を、SQLを使って操作する事ができる。
ps
PID TTY TIME CMD
1121 ttys000 0:00.02 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server login -fp tyabuta
1125 ttys000 0:00.40 -zsh
1414 ttys000 0:15.03 vim memo.md
1416 ttys001 0:00.02 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server login -fp tyabuta
1418 ttys001 0:05.71 -zsh
ps | qq -q "select TTY, count(*) as hoge from stdin group by TTY"
ttys000,3
ttys001,2