I used to have this command to count how many times I have click with a mouse, the command is xev | grep "ButtonPress"
.
my colleague modify the command so that it return:
ButtonPress 0
ButtonPress 1
ButtonPress 2
ButtonPress 3
and so on... Unfortunately he's no longer contactable so I can't reach him anymore.
I recall the involvement of i++
and something like that, how to reproduce the command?
The fact that there's
i++
suggests there was eitherbash
orksh
shell in use,potentiallyawk
orperl
as well. In either case, we can use process substitution<(...)
to feed output ofxev
to counting loop (although simple pipelinexev | while...
could work just fine).text processing tools:
Portably and for fewer key strokes we can use
awk
:perl
version:Shells:
Here's what works in
bash
:In case you don't want spammy output of many lines, we can use
printf
to send control code to clear previous line and output only the running count (that is you'd only see integer value change on the line):Portably in POSIX shell:
basic utils:
For simple, quick, and dirty way we can hack this via
cat -n
with line count being printed on the left instead of right: