tail -fgp para um parágrafo

3

Eu tenho um arquivo de log flutuante que é separado por linhas vazias. É difícil tail com grep 'PID' - quando faço isso, mostra apenas 1 linha.

Esta é a amostra:

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

Eu só quero ver este parágrafo contendo 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]
    
por Erichlong Mezque 12.07.2016 / 13:50

2 respostas

2

Aparentemente, seu separador de registro ( RS ) é [project worklight_server]

Então tente:

... | awk -v RS=".project worklight_server."  '/00000144/' 
    
por JJoao 14.07.2016 / 09:38
2

Se você sabe o valor de X (número de linhas que você quer) ou se uma aproximação vai fazer, você pode colocar isso depois de seu tail

| grep -A 25 00000144

que lhe dará qualquer linha com 00000144 e as próximas 25 linhas.

Se você não sabe X, mas pode marcar onde a saída deve parar, você pode usar sed , por exemplo. Para ir de uma linha com o PID para uma linha com 'project worklight_server':

| sed -n '/00000144/,/project\ worklight_server/p'
    
por Zanna 13.07.2016 / 10:01