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

Awkでログファイルを集計

More than 3 years have passed since last update.

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]}'
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
No 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
ユーザーは見つかりませんでした