xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", %5, %8}
When I use xev there is only a certain bit of information I want. The natural response of using xev to get keycode info looks like this...
KeyPress event, serial 48, synthetic NO, window 0x1600001,
root 0xf6, subw 0x0, time 754405, (348,566), root:(349,620),
state 0x0, keycode 40 (keysym 0x64, d), same_screen YES,
XLookupString gives 1 bytes: (64) "d"
XmbLookupString gives 1 bytes: (64) "d"
XFilterEvent returns: False
KeyRelease event, serial 48, synthetic NO, window 0x1600001,
root 0xf6, subw 0x0, time 754488, (348,566), root:(349,620),
state 0x0, keycode 40 (keysym 0x64, d), same_screen YES,
XLookupString gives 1 bytes: (64) "d"
XFilterEvent returns: False
The result of the AWK script would only return:
40 d
This made me want to learn AWK :)
So after learning about NR and doing a few tutorials, I am now trying to figure this out. First the -F is just divides by fields in this case '[ )]+' I think this is regex for 1 or more of spaces or closing parenthesis. I do not understand this. I do not see any spaces before prenthesis. Also, I do not know what a space in a regex box does here, because I have only learned about whitespace tools such as \s. So I wanted to see what fields dispay with $5 and %8 because it didnt look right in my analysis and I was confused!!
echo "state 0x0, keycode 12 (keysym 0x33, 3), same_screen YES," | awk '{print $8}'
same_screen
echo "state 0x0, keycode 12 (keysym 0x33, 3), same_screen YES," | awk '{print $5}'
(keysym
edit:
So what is this printf "%-3s %s\n", $5, $8}
??
Why is the output so different then my echo example above?
Obviously, this is coming from the magic of {a[NR+2] NR in a}
. Some sort of an array and a for loop.
I look at NR+2 and it makes me think: since when AWK starts NR starts on 1 and adding 2 would make it the third line. This looks right since all of the info I want is on the third line.
What is going on with a[NR+2]? for NR in a printf... ? I understand printf I understand for loops. The way NR is used here baffles me.
I guess the real question is what is happening with 'a'? Is this a predefined thing I don't know about?
$5
and$8
rather than%5
and%8
, surely? You appear to have figured out what the{ a[NR+2] } NR in a ...
does - so what is your question, exactly?