Omar Tariq Omar Tariq - 5 days ago 6
Linux Question

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

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

Or even shorter :

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