Reputation: 25
I have this table:
Source Protocol
10.0.0.6 IGMPv3
10.0.0.6 SSDP
fe80::2998:5ae5:5e72:7f9 SSDP
fe80::2998:5ae5:5e72:7f9 SSDP
a0:48:1c:df:1b:1b ARP
a0:48:1c:df:1b:1b ARP
10.0.0.11 TCP
10.0.0.11 HTTP
Vmware_98:56:e6 ARP
Vmware_98:56:e6 ARP
12.0.0.11 IGMPv6
23.3.1.11 BROWSER
I need to filter the mac addresses without hard coding it, expected output:
Source Protocol
10.0.0.6 HTTP
10.0.0.6 SSDP
10.0.0.11 TCP
10.0.0.11 HTTP
12.0.0.11 IGMPv6
23.3.1.11 BROWSER
Upvotes: 0
Views: 67
Reputation: 67988
(^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.*$)
You can try this as well.just grab the matches or groups.See demo.
http://regex101.com/r/nB2lL9/7
Edit:
In R it will be something like (assuming df
is your data set)
df[grep("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}.*$", df$Source), ]
Upvotes: 1
Reputation: 887891
You could try:
dat[grep("^\\d+\\.\\d+\\.\\d+\\.\\d+$",dat$Source),]
# Source Protocol
#1 10.0.0.6 IGMPv3
#2 10.0.0.6 SSDP
#7 10.0.0.11 TCP
#8 10.0.0.11 HTTP
#11 12.0.0.11 IGMPv6
#12 23.3.1.11 BROWSER
Upvotes: 1