From nobody Sat Apr 2 22:17:26 2022 X-Original-To: questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1DAD81A615A6 for ; Sat, 2 Apr 2022 22:17:35 +0000 (UTC) (envelope-from edgar@pettijohn-web.com) Received: from mail.pettijohn-web.com (pettijohn-web.com [108.61.222.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA512) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4KWBHL1DBHz3kgs for ; Sat, 2 Apr 2022 22:17:34 +0000 (UTC) (envelope-from edgar@pettijohn-web.com) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=dkim; bh=iv1vGaMkJVJqCnh Pon08fPu655cTSrCzcvvwdr6CsWE=; h=in-reply-to:from:references:to: subject:date; d=pettijohn-web.com; b=QaN4T0nvi90mAHJOE2FO+UAKj33qkQmXA CxGJq1ZN33sUXG0SyHa7P//ilk96Z7lBfxtKpRqHqyfJhWYGEmbNQsfcG+zUYKYm32l2tF opalaoeoTAVzcKaSMjknZYdbnWbzMn3ZfNBjGYH3BH8BllVPLbqFFX21iEt8oWI0WRUM= Received: from [10.0.0.251] ( [98.50.132.39]) by mail.pettijohn-web.com (OpenSMTPD) with ESMTPSA id 4fff10fd (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Sat, 2 Apr 2022 17:17:27 -0500 (CDT) Message-ID: Date: Sat, 2 Apr 2022 17:17:26 -0500 List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; OpenBSD amd64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: extracting an IPv4 address from text? Content-Language: en-US To: questions@freebsd.org References: <25160.44484.392802.868667@jerusalem.litteratus.org> From: Edgar Pettijohn In-Reply-To: <25160.44484.392802.868667@jerusalem.litteratus.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4KWBHL1DBHz3kgs X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=pettijohn-web.com header.s=dkim header.b=QaN4T0nv; dmarc=pass (policy=none) header.from=pettijohn-web.com; spf=pass (mx1.freebsd.org: domain of edgar@pettijohn-web.com designates 108.61.222.55 as permitted sender) smtp.mailfrom=edgar@pettijohn-web.com X-Spamd-Result: default: False [-3.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[pettijohn-web.com:s=dkim]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:108.61.222.55]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[questions@freebsd.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; DKIM_TRACE(0.00)[pettijohn-web.com:+]; DMARC_POLICY_ALLOW(-0.50)[pettijohn-web.com,none]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MLMMJ_DEST(0.00)[questions]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:20473, ipnet:108.61.222.0/24, country:US]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N 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