B
B
Bogdan2017-08-22 15:11:58
linux
Bogdan, 2017-08-22 15:11:58

Grep search and block output?

Hello. How to write grep. You need to find the value and output the entire block that starts with
Started and ends with Completed

Started POST "/institution/timesheets/ajax_filter_timesheets" for 127.0.0.1 at 2017-08-22 11:33:31 +0300
Processing by Institution::TimesheetsController#ajax_filter_timesheets as */*
  Parameters: {"date_start"=>"01.08.2017", "date_end"=>"31.08.2017", "sort_field"=>"", "sort_order"=>"", "timesheet"=>{}}
  Rendered institution/timesheets/ajax_filter_timesheets.js.erb (229.2ms)
Completed 200 OK in 780ms (Views: 587.7ms | ActiveRecord: 4.5ms)


Started GET "/institution/timesheets/dates?id=1191" for 127.0.0.1 at 2017-08-22 11:34:22 +0300
Processing by Institution::TimesheetsController#dates as HTML
  Parameters: {"id"=>"1191"}
  [1m[35m (28.0ms)[0m  [1m[33m          UPDATE timesheet_dates SET reasons_absence_id='2' WHERE id = 3083371
[0m
  [1m[36mInstitution Load (1.0ms)[0m  [1m[34mSELECT  "institutions"."id", "institutions"."code", "institutions"."name", "institutions"."branch_id" FROM "institutions" WHERE "institutions"."id" = $1 LIMIT $2[0m  
Completed 200 OK in 582ms (Views: 411.4ms | ActiveRecord: 47.0ms)


Started POST "/institution/timesheets/ajax_filter_timesheet_dates" for 127.0.0.1 at 2017-08-22 11:34:23 +0300
Processing by Institution::TimesheetsController#ajax_filter_timesheet_dates as */*
  Parameters: {"id"=>1191, "field_id"=>"", "timesheet"=>{"id"=>1191}}
  Rendered institution/timesheets/ajax_filter_timesheet_dates.js.erb (5133.9ms)
Completed 200 OK in 13136ms (Views: 5467.0ms | ActiveRecord: 291.2ms)

So far, I just wrote outputs from the beginning of the file and the end of the block.
grep -Pzo "Star(.|\n)*?id = 308(.|\n)*?(?=\n{2})" ./log/development.log

and as a result, only the block is needed
Started GET "/institution/timesheets/dates?id=1191" for 127.0.0.1 at 2017-08-22 11:34:22 +0300
Processing by Institution::TimesheetsController#dates as HTML
  Parameters: {"id"=>"1191"}
  [1m[35m (28.0ms)[0m  [1m[33m          UPDATE timesheet_dates SET reasons_absence_id='2' WHERE id = 3083371
[0m
  [1m[36mInstitution Load (1.0ms)[0m  [1m[34mSELECT  "institutions"."id", "institutions"."code", "institutions"."name", "institutions"."branch_id" FROM "institutions" WHERE "institutions"."id" = $1 LIMIT $2[0m  
Completed 200 OK in 582ms (Views: 411.4ms | ActiveRecord: 47.0ms)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xp3, 2017-08-22
@xp3

cat test.txt | grep -oPz "^Started[\s\S]*?^Completed"

I
Ingvar, 2017-08-24
@take

grep 'Parameters:' -C 2
I found a more flexible and accurate answer on the Internet:
link to many examples

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question