pipe-combinations

上級
1/10
user@linux:~/workspace$
cat logs/app.log | grep -i "error" | wc -l

解説

  1. cat logs/app.log でログを出力
  2. grep -i "error" で大文字小文字を無視してエラー行のみ抽出(仮想環境のログでは [ERROR] 行が 1 件のみ存在)
  3. wc -l で行数をカウント
1[INFO] 2026-01-13 09:00:00 Application started
2[DEBUG] 2026-01-13 09:00:05 Loading configuration from config/app.conf
3[INFO] 2026-01-13 09:00:10 Database connection established
4[DEBUG] 2026-01-13 09:00:15 Cache initialized (Redis)
5[INFO] 2026-01-13 09:00:20 Server listening on port 3000
6[WARN] 2026-01-13 09:15:30 High memory usage detected: 85%
7[ERROR] 2026-01-13 09:30:45 Failed to process payment: timeout
8[INFO] 2026-01-13 09:31:00 Payment retry successful
9[DEBUG] 2026-01-13 09:45:00 Processed 1523 requests in last hour
10[INFO] 2026-01-13 10:00:00 Daily backup completed