Ich fürchte, grep hat keine solche Möglichkeit. Perl und / oder Python könnte. Aus dem Kopf (ohne viel darüber nachzudenken) habe ich mir die folgende Awk-Combo ausgedacht.
awk '/Started GET/{print ""};1' blurble | awk 'BEGIN{RS=ORS="\n\n";FS=OFS="\n"}/FATAL/{print $0}'
Ausgehend von einem Protokollblock, der aus Ihrem Snippet (x4) erstellt wurde, und ein paar zusätzlichen "other log" -Zeilen, die eingeworfen und zwei "FATAL" -Zeilen entfernt wurden, werden zwei Segmente gedruckt:
[----] I, [2014-04-10T19:12:36.294512 #1910:e93004] INFO -- : Started GET "/ems_infra/new" for 4.2.2.2 at 2014-04-10 15:12:36 -0400
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.369320 #1910:e93004] INFO -- : Completed 200 OK in 69ms (Views: 22.5ms | ActiveRecord: 0.0ms)
[----] I, [2014-04-10T19:12:36.294512 #1910:e93004] INFO -- : Started GET "/ems_infra/new" for 4.2.2.2 at 2014-04-10 15:12:36 -0400
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] F, [2014-04-10T19:12:36.346380 #1910:e93004] FATAL -- : Error caught: [NoMethodError] undefined method `invert' for nil:NilClass
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.369320 #1910:e93004] INFO -- : Completed 200 OK in 69ms (Views: 22.5ms | ActiveRecord: 0.0ms)
[----] I, [2014-04-10T19:12:36.294512 #1910:e93004] INFO -- : Started GET "/ems_infra/new" for 4.2.2.2 at 2014-04-10 15:12:36 -0400
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.369320 #1910:e93004] INFO -- : Completed 200 OK in 69ms (Views: 22.5ms | ActiveRecord: 0.0ms)
[----] I, [2014-04-10T19:12:36.294512 #1910:e93004] INFO -- : Started GET "/ems_infra/new" for 4.2.2.2 at 2014-04-10 15:12:36 -0400
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] F, [2014-04-10T19:12:36.346380 #1910:e93004] FATAL -- : Error caught: [NoMethodError] undefined method `invert' for nil:NilClass
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.369320 #1910:e93004] INFO -- : Completed 200 OK in 69ms (Views: 22.5ms | ActiveRecord: 0.0ms)
Das Ausführen der beiden awks gegen die Datei (ich nannte sie blurble) ergibt diese Ausgabe:
[----] I, [2014-04-10T19:12:36.294512 #1910:e93004] INFO -- : Started GET "/ems_infra/new" for 4.2.2.2 at 2014-04-10 15:12:36 -0400
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] F, [2014-04-10T19:12:36.346380 #1910:e93004] FATAL -- : Error caught: [NoMethodError] undefined method `invert' for nil:NilClass
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.369320 #1910:e93004] INFO -- : Completed 200 OK in 69ms (Views: 22.5ms | ActiveRecord: 0.0ms)
[----] I, [2014-04-10T19:12:36.294512 #1910:e93004] INFO -- : Started GET "/ems_infra/new" for 4.2.2.2 at 2014-04-10 15:12:36 -0400
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] F, [2014-04-10T19:12:36.346380 #1910:e93004] FATAL -- : Error caught: [NoMethodError] undefined method `invert' for nil:NilClass
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.345863 #1910:e93004] INFO -- : other random logs
[----] I, [2014-04-10T19:12:36.369320 #1910:e93004] INFO -- : Completed 200 OK in 69ms (Views: 22.5ms | ActiveRecord: 0.0ms)