I'm currently writing a program in python on Ubuntu. I have the requirement of reading log file.The log file is updating continually.My requirement is to read only updating list.For example first log file contain log file:
abc1
abc2
abc3
and after some time i update log file with
abc4
abc5.
abc6 and so on..
So every time we have to read only the updated list( like abc4 and abc5..). So to avoid the more memory i just want read only updated list instead of reading whole log file in Python.I am not getting the logic.I just write to read last two lines in log file.please help.
Python Code:
import time
templog = 'file name'
while 4:
with open(templog,'r') as f:
logstr = f.readlines()
print(f.readline())
if f:
current_line = f.readlines()
for line in logstr:
previous_line = current_line
current_line=line
print(previous_line)
print(current_line)
time.sleep(1)