Omar Tariq Omar Tariq - 1 year ago 59
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
(in current case).

Something like this:-

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

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

Or even shorter :

xinput --list |grep -oP 'Mouse.*id=\K.*?(?=\s)' 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download