1
1

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.

Awkでログファイルを集計

Last updated at Posted at 2016-04-26

Awkでログファイルを集計したいときに使います

最初の行を取得

awk 'NR == 1' aa.log

最終行を取得

awk 'END {print}' aa.log

該当行をカウントする

awk '$8>0{count++} END {print count}' a.log'

列を合計する

echo -n "si total: " >> ${mylog}
SIALL=`awk '{m+=$8} END{print m}' ${myfile}`
echo $((SIALL/1000)) MB >> ${mylog}

ログファイルの該当行を抜き出す

awk '$8 == "si" {print $0}' aaa.log

ログファイルから必要な日時を取り出す

cat test.csv | awk '$1 ~ /20151214/ {print}'

ログファイルに行番号をつけて出力

cat test.csv | awk '$1 ~ /20151214/ {print NR "\t" $0}'

ログファイルの指定行を抜き出し

awk  'NR==103240, NR==225590 {print $0}' test.csv > aa.txt

ログファイルの指定行番号のみ吐かせる

出力

cat test.csv | awk '$1 
~ /20151214/ 
{print NR "\t" }'

Awkでsplitと同じことをする

echo 'aaa,bbb,ccc' | awk '
{n=split($0, array, ",")} 
END{print n, array[n]}'
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?