I'm trying to see how many times foo bar
appears in /var/log/foo.log
within an arbitrary amount of time on a remote server, but nothing that I've tried so far has worked.
I've already got a timer script that I use to keep track of how long it has been since I started tailing /var/log/foo.log
, and now I'd just like a way to tell how many times foo bar
has appeared in the tailed output.
I searched google, but I didn't find anything pertinent within the first 10 pages of results.
Here's what I've tried with frustrating results:
## works on local machine, but doesn't work as expected on remote
tail -f /var/log/foo.log | grep foo\ bar | sed '='
## works on local, but not remote
tail -f /var/log/foo.log | grep foo\ bar | cat -n -
## works on local, but not remote
tail -f /var/log/foo.log | grep foo\ bar | awk -F'\n' '{printf "[%d]> ", NR; print $1}'
I even tried to write a sed script that'd act like tail -f
, but I made limited-to-no headway with that.
NOTE
the remote server is running an older version of coreutils, and upgrading is an option, but is NOT in any way the desired solution.
--line-buffered
option togrep
. Ortail -f ... | awk '/foo bar/{print ++n, $0}'
tail -f /var/log/log.log | awk '{ printf "[%d]> %s\n", NR+1 ,$0; fflush(stdout); }'