Telegraf logparser to count lines in a file?

I want to count the number of lines in a file with no conditions - literally just a count of lines in a file.
Ideally, I would like to count the number of lines where “mystring” appears anywhere in a line of that file. I can’t seem to figure out how to use grok if the messages have different formats. Please help.

I think the easiest method to implement this would be with the exec input plugin and a script like:

#!/bin/sh
filename=metrics.go
value=$(cat "$filename" | wc -l || 0)
echo "foo,file="$filename" lines=$value"

That’s basically what I ended up doing. Thanks for replying!
I’ve also been trying to execute the $(cat "$filename" | wc -l || 0) part in the commands = [ ] of the telegraf.conf’s inputs.exec:
’ commands = [ " ‘echo foo,logfile=afile message_count=$(cat “/var/log/httpd/access_log” | wc -l || 0)’ "] '
but to no avail.

The command is ran without a shell, so it can’t interprete some of the shell syntax in this command. You could try this, but I’d probably stick with a separate shell script since quoting can get tricky:

commands = ['''bash -c 'echo foo,logfile=afile message_count=$(cat "/var/log/httpd/access_log" | wc -l || 0)' ''']