1

I am using xinput to get the following data:

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ AlpsPS/2 ALPS DualPoint TouchPad          id=10   [slave  pointer  (2)]
⎜   ↳ AlpsPS/2 ALPS DualPoint Stick             id=11   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Video Bus                                 id=8    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=9    [slave  keyboard (3)]
    ↳ ThinkPad Extra Buttons                    id=12   [slave  keyboard (3)]
    ↳ Integrated Camera: Integrated C           id=13   [slave  keyboard (3)]

My intention is to retrieve the id of AlpsPS/2 ALPS DualPoint Stick in one line only. So, I tried the following:

xinput | grep -Po "(?<=DualPoint Stick\s.+id=())"
grep: lookbehind assertion is not fixed length

What am I doing wrong?

Echchama Nayak
  • 971
  • 3
  • 23
  • 44
  • PCRE only supports fixed length look behind. No repetition operators like `+`. Not sure why you're using look behind in the first place though. – Shawn Oct 07 '19 at 16:51
  • Please edit your Q to show your required output from that sample input. Good luck. – shellter Oct 07 '19 at 17:18
  • And why always make it so hard, `sed '/^.*DualPoint Stick * id=/s///;s/ .*$//'` (or very close anyway). Good luck. – shellter Oct 07 '19 at 17:21

2 Answers2

2

With GNU grep:

xinput | grep -Po 'AlpsPS/2 ALPS DualPoint Stick *id=\K[0-9]+'

Output:

11

See: What does grep -Po '…\K…' do? How else can that effect be achieved?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
0

For posterity who might be on an HP laptop looking for touchpad help,

xinput | grep -Po '.*Touchpad\s+id=\K[0-9]+
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103