Tail file - count the number of lines with a given pattern

I need to ensure that a certain line appears in the active log file, which means that the operation is active (submitting this account to the trigger).

Given that I will do this remotely, I cannot go with the 'tail -f filename', otherwise it will follow the file indefinitely, so I think about grabbing a bunch of the last lines written and counting them as

tail -n8 /var/log/service/service_V138/operations.log| grep \|DONE\| | wc -l 

Is there a better way?

+4
source share
2 answers

You can improve this a bit by removing the pipe to wc and using grep -c .

 tail -n8 /var/log/service/service_V138/operations.log | grep -c \|DONE\| 
+4
source

less + F -N somelogfile.log? pattern simple and easy

+1
source

All Articles