How can I set the grep after context to be “until the next blank line”?

后端 未结 4 1101
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 13:31

With grep I know how to set the context to a fixed number of lines. Is it possible to show a context based on an arbitrary string condition, like set after-context to \"until th

4条回答
  •  旧时难觅i
    2021-01-30 13:46

    A simple solution is:

    awk '/pattern/' RS= input-file
    

    Setting RS to the empty string makes awk treat blank lines as the record separator, and the simple rule /pattern/ causes awk to print any record that matches the pattern, which can be any extended regular expression.

提交回复
热议问题