Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Apr 2022 17:17:26 -0500
From:      Edgar Pettijohn <edgar@pettijohn-web.com>
To:        questions@freebsd.org
Subject:   Re: extracting an IPv4 address from text?
Message-ID:  <b2982d76-5edd-2cd0-1cae-83709afa6a39@pettijohn-web.com>
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 4/2/22 15:10, 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?
>
>
> 				Hopefully,
>
>
> 					Robert Huff
>
>
>
>
> 				
>

If perl is available:


$ perl -MRegexp::Common='net' -n -e "print if $_ =~ $RE{net}{IPv4}" 
/path/to/logfile


Edgar




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?b2982d76-5edd-2cd0-1cae-83709afa6a39>