Command /pts/d;
delete all lines, that contain string pts
.
Try this:
who | sed -e '/orschiro/! d; /pts/! d; s/^.*\(:[0-9.]\+\).*$/\1/p;d' | head -n1
Question
I want to find out the used DISPLAY of the currently logged in user. For that I wanted to use sed
. First, the output of who
:
[orschiro@thinkpad ~]$ who
orschiro tty1 2013-08-05 23:15
orschiro pts/0 2013-08-05 23:17 (:0)
orschiro pts/1 2013-08-05 23:22 (:0)
orschiro pts/2 2013-08-05 23:22 (:0)
That is I want to retrieve :0
for the logged in user orschiro
.
I am using the following expression but it does not retrieve the expected result. Instead the output is empty:
[orschiro@thinkpad ~]$ who | sed -e "/orschiro/! d;/pts/d;s/^.*[^0-9]\\(:[0-9.]\\+\\).*$/\\1/p;d" | head -n1
[orschiro@thinkpad ~]$
What is wrong with my expression?
Solution
Command /pts/d;
delete all lines, that contain string pts
.
Try this:
who | sed -e '/orschiro/! d; /pts/! d; s/^.*\(:[0-9.]\+\).*$/\1/p;d' | head -n1
OTHER TIPS
Maybe this?
who | awk -F '[()]' '/orschiro/{print $(NF-1)}' | grep -v orschiro | head -n1
or
who | awk -F '[()]' '/orschiro/{print $(NF-1)}' | grep -v orschiro | uniq
Try this one:
who | awk '/orschiro/{print $5}' | sed -e 's/[()]//g'