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;}'

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


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:


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

  • 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.