3

I'm trying to create a utility for extracting the first display that a user is physically at using grep and awk:

$ w | grep -P '^naftuli' | awk '{print $3;}'
:0
reprisal
tmux(2464).%0
tmux(2464).%1
tmux(2464).%2

I have seen variant X session identifiers, is there a standard format that I could implement a regular expression for?

2

On a modern Unix system, there are two types of X displays: local or (TCP) remote. A local display name is : followed by a number, and optionally but rarely followed by . and a screen number. A remote display is a host name or IP address followed by a local display name. Thus, in ERE syntax:

/([-.0-9A-Za-z]+|\[[0-9A-Fa-f:]\]):[0-9]+(\.[0-9]+)?/

In practice, “it's X if and only if there's a :” should work.

1
  • Thank you, as always Gilles, just got back to this today for this. – Naftuli Kay Mar 5 '17 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.