Search This Blog

Tuesday, February 17, 2009

Extracting IP's from output of who command using grep

[root@vikas ~]# who
root tty7 2009-02-17 11:23 (:0)
root pts/0 2009-02-17 12:30 (:0.0)
root pts/1 2009-02-17 12:32 (:0.0)
root pts/2 2009-02-17 12:32 (:0.0)
root pts/3 2009-02-17 13:33 (192.168.4.35)
root pts/4 2009-02-17 14:23 (192.168.4.15)

who | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
who | grep -o '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*'

192.168.4.35
192.168.4.15

No comments:

Post a Comment