LoginSignup
0
1

More than 5 years have passed since last update.

awkメモ

Last updated at Posted at 2017-06-05

オークと読むらしい.
sed や grep のようなテキスト処理ツールに演算機能を持たせた拡張ツール.
効率的にテキストファイルを処理でき、CSV や TSV 形式のファイルを簡易に処理できる.
while, if とか普通にプログラミングできる.

-F

区切り文字を変更

awk -F, '{print $1}'

出力結果を「,」区切りにし、1列目を出力

NR

行数を表す

ORS

出力レコード区切り文字

awk '{if(NR%100)ORS=",";else ORS="\n";print}'

出力結果をカンマ区切り 100件毎に改行いれる

if

tail -f access.log | awk '{if($8 >= 400) {print $0}}'

アクセスログから http ステータスコード 400 以上を出力する

qコマンド

csv, tsv に対して、 sql を使えるコマンド

cat test.csv | q -d , "select c1 from - "

-d ・・・ 区切り文字指定
c1 ・・・ カラム指定 (この場合 1番目)
- ・・・ 標準入力されたもの. csv 等のファイル名入れてもいい

0
1
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
0
1