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

grepでパターンにマッチした文字列だけを出力する(-o オプション)

More than 1 year has passed since last update.

たまにしか使わなくてよく忘れるのでメモ。

実際にはこんなシチュエーションだった。

postfixのメールログからステータスの統計とろうとしていた。
しかし、postfixのログフォーマット的に、status=xxx の現れる位置が
スペース区切りで考えてもカンマ区切りで考えても一定にならないので
cutawk では切り出せなくて1
なんか方法ないかな・・・と調べていて
grep-o オプションでできることに気づいた。

$ grep -E -o ”status=\S+” /var/log/maillog | sort | uniq -c
   1386 status=bounced
  40125 status=deferred
    167 status=expired,
   7197 status=sent

めっちゃエラー出てた:sweat_smile:
(このエラーはその後無事に解消した)


  1. awk にあまり詳しくないので何かやり方あるのかもしれないが当時は思いつかなかった。 

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