From 95a473a22dbd666ef54daeb56dbd2015a58ad7bb Mon Sep 17 00:00:00 2001 From: "Stephen McQuay (smcquay)" Date: Tue, 3 Apr 2018 09:42:10 -0700 Subject: [PATCH] find space-delimited ip address anywhere in line I'd prefer this were more robust and perhaps used a regexp. --- main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 65e1408..3f7790d 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "net" "os" "sort" + "strings" ) type lines []string @@ -16,7 +17,19 @@ type lines []string func (l lines) Len() int { return len(l) } func (l lines) Swap(i, j int) { l[i], l[j] = l[j], l[i] } func (l lines) Less(i, j int) bool { - a, b := net.ParseIP(l[i]), net.ParseIP(l[j]) + var a, b net.IP + for _, s := range strings.Fields(l[i]) { + a = net.ParseIP(s) + if a != nil { + break + } + } + for _, s := range strings.Fields(l[j]) { + b = net.ParseIP(s) + if b != nil { + break + } + } return bytes.Compare(a, b) < 0 }