سؤال

Is there a program that would result in output like "wc -l" but that would update counter on more data.

Here is what I want it for:

tail -f log/production.log | grep POST | wc -l

But wc -l should be changed for something.

هل كانت مفيدة؟

المحلول

tail -f log/production.log | grep --line-buffered POST | awk '{printf "\r%d", ++i} END {print ""}'

This prints the line count after every line of input. The carriage return \r makes each line number overwrite the last, so you only see the most recent one.

Use grep --line-buffered to make grep flush its output after each line rather than every 4KB. Or you can combine the grep and awk into one:

tail -f log/production.log | awk '/POST/ {printf "\r%d", ++i} END {print ""}'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top