问题描述:

I have a server that I cannot access the log files directly. For security reasons, access to the logs is via a script that executes the less command.

The contents of the log file are similar to:

08:03:52,143 DEBUG sessionid1111111 [za.co.phuthib.Service1] (http-/0.0.0.0:8905-4) initialiseProperties(): currentDate: 20160812

08:03:52,143 DEBUG sessionid1111111 [za.co.phuthib.Service1] (http-/0.0.0.0:8905-4) cached object found

08:03:52,143 INFO sessionid1111111 [za.co.phuthib.Service2] (http-/0.0.0.0:8905-4) passphrase: 243989895859385938394583945839548983423488234

08:03:52,143 INFO sessionid1111111 [za.co.phuthib.Service2] (http-/0.0.0.0:8905-4) chanellID: [CHANNELID]

08:03:52,144 INFO sessionid1111111 [za.co.phuthib.Service3] (http-/0.0.0.0:8905-4) POST: /za/co/phuthib/retrieveProductList/

08:03:52,144 INFO sessionid1111111 [za.co.phuthib.Service3] (http-/0.0.0.0:8905-4) Input: {"id":"3989349"}

08:03:52,812 INFO sessionid1111111 [za.co.phuthib.Service3] (http-/0.0.0.0:8905-4) Response code [200 OK])

The server accepts many requests from many users and as such one needs to search through the file to find the information they need.

I am able to search for sessionid1111111 and am also able to search for za.co.phuthib.Service3 independantly.

I am trying to search for za.co.phuthib.Service3 and sessionid1111111.

I tried it with regular expressions but cannot seem to get it working, for example:

/sessionid1111111[\s]Service3

网友答案:

The regex pattern that is precise (will match only the Service3 in the [...] with phuthib inside:

sessionid1111111 +\[za\.co\.phuthib\.Service3]

Note that here, + matches 1 or more spaces, \[ matches a literal [ and a \. matches a literal ..

If you do not need that level of precision, just use

sessionid1111111.*Service3

or a shorter

sessionid1{7}.*Service3

Where .* matches 0+ chars, as many as possible, and 1{7} matches seven consecutive 1 chars.

Note that sessionid1{7}.*Service3 will also find a match in sessionid111111111122234567 [za.co.phuthib.Service1] (http-/0.0.0.0:8905-4) Input: {"name":"Service3"}, that is why I strongly recommend making your pattern as precise as can be.

相关阅读:
Top