0

I'm trying to find the value after "pts/" with this output from who:

someUsersome        tty7         2019-05-09 00:19 (:0)
someUsername        pts/0        2019-05-11 19:11 (:0)
someUsername        pts/4        2019-05-11 19:25 (:0)
someUsername        pts/5        2019-05-11 19:25 (:0)
someUsername        pts/6        2019-05-11 19:25 (:0)

I'm close with using tail to get the last line, but how do I get just the number after "pts/" only (i.e. no unnecessary white space) which I assume could be any number, perhaps even sometimes higher than a single digit?

I've fiddled with grep -o but can't get the matching right because of the date:

who | tail -n1 | grep -oP 'pts/\K.*'

Cyrus
  • 84,225
  • 14
  • 89
  • 153
nooblag
  • 678
  • 3
  • 23

0 Answers0