1. Interception period

Scenario 1: Capture logs between 2019-06-25 10:10 and 2019-06-25 10:20. Apollo-service. log is the name of the file you want to capture, and new2.log is the name of the file you want to save the log after capturing.

sed -n '/2019-06-25 10:10/, /2019-06-25 10:20/p' catalina.out  > new1.log
sed -n '/2019-06-25 10:20:47/, /2019-06-25 10:26:47/p' catalina.out  > new2.log
sed -n '/ 2019-06-25 10:20:47. 728 /, / 2019-06-25 10:26:47. 728 / p' catalina.out  > new3.log
Copy the code

Scenario 2: I want to check the log information in the shop-bussiness.log.2018-11-06 file between 11:34 and 11:37 on November 6, 2018. I can do this:

grep   '2018-Nov-06 11:3[4-7]' shop-bussiness.log.2018-11-06
Copy the code

Second, intercept the number of rows

Take the new.log file from catalina.out at lines 100-500 and save it.

 sed -n '100500'p apollo-service.log > new.log
Copy the code

3. View N lines of logs

Tail -n 10 test.log Queries the last 10 lines of a log. Tail -n +10 test.log Queries all logs generated after 10 rows. Head -n 10 test.log Queries the first 10 lines of a log file. Head-n-10 test.log Queries all logs except the last 10 lines in the log file.Copy the code

Scenario 1: View by Line number: Logs near keywords are filtered out

cat -n test.log |grep "Terrain"
cat -n test.log |tail -n +92|head -n 20
Copy the code

Tail -n +92 Query logs after 92 rows head -n 20 Query the first 20 records in the previous query result