我有一个流动的日志文件,文件间以空行分隔。这很困难tail
-grep 'PID'
当我这样做时,它只显示一行。
这是示例:
[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]
答案1
显然你的记录分隔符(RS
)是[project worklight_server]
因此尝试一下:
... | awk -v RS=".project worklight_server." '/00000144/'
答案2
如果你知道 X 的值(你想要的行数)或者可以用近似值,那么你可以把它放在tail
| grep -A 25 00000144
这将为您提供任何包含 00000144 的行以及接下来的 25 行。
如果您不知道 X 但可以标记输出应该停止的位置,则可以使用sed
例如。要从包含 PID 的行转到包含“project worklight_server”的行:
| sed -n '/00000144/,/project\ worklight_server/p'