LoginSignup
2
2

More than 5 years have passed since last update.

複数のログの行数をカウントするスクリプト

Posted at

ログファイルの行数をそれぞれカウントさせたかったので
awkでスクリプト作ってみた

count.awk
#/usr/bin/gawk -f
BEGIN {
  FS = ":";
  for (i = 1;i < ARGC;i ++) {
    cnt = 0;
    while(getline < ARGV[i] > 0) {
      cnt ++;
    }
    print ARGV[i]":"cnt
  }
}

使い方

awk -f count.awk /var/log/httpd/access_log*

/var/log/httpd/access_log:28
/var/log/httpd/access_log.1:141
/var/log/httpd/access_log.2:131
/var/log/httpd/access_log.3:185
/var/log/httpd/access_log.4:153

こんな感じで出力されます

2
2
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
2
2