Use grep and sed to intercept logs for a period of time
Assuming the log name: out.log, the way to record the date and time in the log is: 2021-07-09 17:06:21 log text
1. The easiest way to use grep
Command: grep 'time' 'log file name'
grep "2021-07-09 11:5[0-9]" out.log > log.txt
to intercept 10 minutes of content
2. sed uses
sed -n '/2021-07-09 16:14:00/,/2021-07-09 16:14:35/p' out.2021-07-09 > log.txt
to intercept 35 seconds Log
The start time and end time must have a record corresponding to the time in the log file. If the
start time is not intercepted, nothing will be intercepted, and if the end time is not, the content will be intercepted to the end of the entire day.
0 Comments