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
  • 77,979
  • 13
  • 71
  • 125
nooblag
  • 582
  • 2
  • 16

0 Answers0