Skip to content
Advertisement

Bash – Retrieve ID From A String (xinput) Received From A Pipe

When I run the following command it returns me the information of my current mouse:-

$ xinput --list | grep "Mouse"
⎜   ↳ A4Tech USB Mouse                          id=13   [slave  pointer  (2)]

What command should I execute (maybe along with some regex) that I can get an output 13 (in current case).

Something like this:-

$ xinput --list | grep "Mouse" | ANOTHER_COMMAND
13

Advertisement

Answer

  xinput --list | grep "Mouse" |grep -oP 'id=K.*?(?=s)'

Or even shorter :

xinput --list |grep -oP 'Mouse.*id=K.*?(?=s)' 
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement