문제

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