質問

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