Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Apr 2022 16:41:38 -0400 (EDT)
From:      Daniel Feenberg <feenberg@nber.org>
To:        Robert Huff <roberthuff@rcn.com>
Cc:        questions@freebsd.org
Subject:   Re: extracting an IPv4 address from text?
Message-ID:  <69e069b9-49a5-cc90-73c-ad4da09ae9e4@nber.org>
In-Reply-To: <25160.44484.392802.868667@jerusalem.litteratus.org>
References:  <25160.44484.392802.868667@jerusalem.litteratus.org>

next in thread | previous in thread | raw e-mail | index | archive | help



On Sat, 2 Apr 2022, Robert Huff wrote:

>
> Hello:
> 	Let's suppose I want to parse a line from auth.log and extract
> the IP address (if any) to stdout.
> 	I'm assuming there is a robust way to do this using standard
> command-line tools ... but my brain is flailing on the exact method.
> Anyone have a example they'd be willing to share?  Or is this a
> problem already solved?

How about:

cat auth.log | tr " " "\n" | grep "\." | grep -v "\[" | grep -v "[a-zA-Z]"

or something similar, although I am sure there will be a few strays slip 
through.

Daniel Feenberg



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69e069b9-49a5-cc90-73c-ad4da09ae9e4>