import time
t9=time.strptime("2030-01-02 09:00:00","%Y-%m-%d %H:%M:%S")
t12=time.strptime("2030-01-02 12:00:00","%Y-%m-%d %H:%M:%S")
with open("/root/myweb.log", mode="r") as fr:
for item in fr.readlines():
t = time.strptime(item[:19], "%Y-%m-%d %H:%M:%S")
if t9 < t < t12:
print(item, end="")
with open("/root/log01",mode="a") as fw:
fw.write(item)
[root@localhost ~]
2030-01-02 09:23:12 ccccccccccccccccccccc
2030-01-02 10:56:13 ddddddddddddddddddddddddddd
2030-01-02 11:38:19 eeeeeeeeeeeeeeee
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19