Joao Figueiredo
Joao Figueiredo

Reputation: 3188

tail file - count number of lines with a given pattern

I need to guarantee that a specific string is appearing in an active log file, meaning an operation is alive (feeding this count to a Trigger).

Considering I'll do this remotely, I can't go with 'tail -f filename' else it would follow the file indefinitely, thus I'm thinking about grabbing a bunch of last written lines and counting them as,

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

Is there any better way?

Upvotes: 4

Views: 9863

Answers (2)

carlos g
carlos g

Reputation: 11

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

Upvotes: 1

dogbane
dogbane

Reputation: 274612

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

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

Upvotes: 4

Related Questions