хвост-f grep для одного абзаца

У меня есть плавный файл журнала, который разделяется пустыми строками. Трудно tail это с grep 'PID' - когда я делаю это, это показывает только 1 строку.

Это - Образец:

[7/12/16 17:00:12:206 WIB] 0000013d ht.integration.js.JavaScriptIntegrationLibraryImplementation I {
} [project worklight_server]

[7/12/16 17:00:12:382 WIB] 00000144 ht.integration.js.JavaScriptIntegrationLibraryImplementation I {
"array": [
  {
     "activation_aging": 60,
     "api_temp_path": "\/opt\/lampp\/htdocs\/advanced\/api\/web\/temp\/",
     "backend_temp_path": "\/opt\/lampp\/htdocs\/advanced\/backend\/web\/temp\/",
     "cc_number": "1500599",
     "common_id": 1,
     "credit_interest_rate": "11.20",
     "enable_otr_new": 1,
     "enable_otr_owned": 1,
     "env_info": "DEV",
     "insurance_interest_rate": 20,
     "is_contract_mandatory": 1,
     "min_dp_percentage": 20,
     "otr_threshold": 10000000,
     "radius_length": 10,
     "spa_words": "cumigalak",
     "token_aging": 10
  }
],
"isSuccessful": true,
"responseHeaders": {
  "Connection": "Keep-Alive",
  "Content-Length": "625",
  "Content-Type": "text\/html; charset=UTF-8",
  "Date": "Tue, 12 Jul 2016 09:59:38 GMT",
  "Keep-Alive": "timeout=5, max=99",
  "Server": "Apache\/2.4.17 (Unix) OpenSSL\/1.0.1p mod_perl\/2.0.8-dev Perl\/v5.16.3",
  "X-Powered-By": "Nintriva <nintriva.com>"
},
"responseTime": 46,
"statusCode": 200,
"statusReason": "OK",
"totalTime": 47
} [project worklight_server]
[7/12/16 17:00:12:406 WIB] 0000013d ht.integration.js.JavaScriptIntegrationLibraryImplementation I {
"imei": "5957389338873327"
} [project worklight_server]
[7/12/16 17:00:12:610 WIB] 0000013d com.worklight.integration.model.ProcedureInvoker             W FWLSE0319W: Backend response content type 'json' did not match the expected content type 'text/html', continue prossesing the response. The request and response headers and body: request:
/advanced/api/web/common/generate/
imei=5957389338873327

response:
OK
Date=Tue, 12 Jul 2016 09:59:39 GMT
Server=Apache/2.4.17 (Unix) OpenSSL/1.0.1p mod_perl/2.0.8-dev Perl/v5.16.3
X-Powered-By=Nintriva <nintriva.com>
Content-Length=66
Keep-Alive=timeout=5, max=98
Connection=Keep-Alive
Content-Type=text/html; charset=UTF-8
[project worklight_server]
[7/12/16 17:00:12:611 WIB] 0000013d ht.integration.js.JavaScriptIntegrationLibraryImplementation I {
"data": {
  "token_id": "xxx"
},
"isSuccessful": true,
"responseHeaders": {
  "Connection": "Keep-Alive",
  "Content-Length": "66",
  "Content-Type": "text\/html; charset=UTF-8",
  "Date": "Tue, 12 Jul 2016 09:59:39 GMT",
  "Keep-Alive": "timeout=5, max=98",
  "Server": "Apache\/2.4.17 (Unix) OpenSSL\/1.0.1p mod_perl\/2.0.8-dev Perl\/v5.16.3",
  "X-Powered-By": "Nintriva <nintriva.com>"
},
"responseTime": 203,
"status": 1,
"statusCode": 200,
"statusReason": "OK",
"totalTime": 203
} [project worklight_server]
[7/12/16 17:00:12:800 WIB] 00000144 
something line 1
something line 2
[project worklight_server]

Я просто хочу видеть, что этот абзац содержит PID = 00000144

[7/12/16 17:00:12:382 WIB] 00000144 ht.integration.js.JavaScriptIntegrationLibraryImplementation I {
"array": [
  {
     "activation_aging": 60,
     "api_temp_path": "\/opt\/lampp\/htdocs\/advanced\/api\/web\/temp\/",
     "backend_temp_path": "\/opt\/lampp\/htdocs\/advanced\/backend\/web\/temp\/",
     "cc_number": "1500599",
     "common_id": 1,
     "credit_interest_rate": "11.20",
     "enable_otr_new": 1,
     "enable_otr_owned": 1,
     "env_info": "DEV",
     "insurance_interest_rate": 20,
     "is_contract_mandatory": 1,
     "min_dp_percentage": 20,
     "otr_threshold": 10000000,
     "radius_length": 10,
     "spa_words": "cumigalak",
     "token_aging": 10
  }
],
"isSuccessful": true,
"responseHeaders": {
  "Connection": "Keep-Alive",
  "Content-Length": "625",
  "Content-Type": "text\/html; charset=UTF-8",
  "Date": "Tue, 12 Jul 2016 09:59:38 GMT",
  "Keep-Alive": "timeout=5, max=99",
  "Server": "Apache\/2.4.17 (Unix) OpenSSL\/1.0.1p mod_perl\/2.0.8-dev Perl\/v5.16.3",
  "X-Powered-By": "Nintriva <nintriva.com>"
},
"responseTime": 46,
"statusCode": 200,
"statusReason": "OK",
"totalTime": 47
} [project worklight_server]

[7/12/16 17:00:12:800 WIB] 00000144
something line 1
something line 2
[project worklight_server]
2
задан 16 October 2016 в 00:42

2 ответа

По-видимому, Ваш разделитель записей (RS) [project worklight_server]

Так попытка:

... | awk -v RS=".project worklight_server."  '/00000144/' 
2
ответ дан 2 December 2019 в 02:51

Если Вы знаете значение X (количество строк, Вы хотите), или если приближение сделает, можно поместить это после Вашего tail

| grep -A 25 00000144

, который даст Вам любую строку с 00000144 и следующие 25 строк.

, Если Вы не знаете X, но можно отметить, где вывод должен остановиться, Вы могли использовать sed, например. Добираться от строки с PID к строке с 'проектом worklight_server':

| sed -n '/00000144/,/project\ worklight_server/p'
1
ответ дан 2 December 2019 в 02:51

Другие вопросы по тегам:

Похожие вопросы: