From owner-freebsd-questions@FreeBSD.ORG Fri Jan 18 17:28:33 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4091C16A419 for ; Fri, 18 Jan 2008 17:28:33 +0000 (UTC) (envelope-from jhary@unsane.co.uk) Received: from unsane.co.uk (www.unsane.co.uk [85.233.185.162]) by mx1.freebsd.org (Postfix) with ESMTP id A70D613C4F6 for ; Fri, 18 Jan 2008 17:28:32 +0000 (UTC) (envelope-from jhary@unsane.co.uk) Received: from prawn.unsane.co.uk (150.117-84-212.staticip.namesco.net [212.84.117.150]) (authenticated bits=0) by unsane.co.uk (8.14.0/8.14.0) with ESMTP id m0IHR82d050522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 18 Jan 2008 17:27:09 GMT (envelope-from jhary@unsane.co.uk) Message-ID: <4790E1BB.2020001@unsane.co.uk> Date: Fri, 18 Jan 2008 17:28:27 +0000 From: Vince Hoffman User-Agent: Thunderbird 2.0.0.9 (X11/20071116) MIME-Version: 1.0 To: Paul Schmehl References: <043D043618599C4017DE8774@utd59514.utdallas.edu> In-Reply-To: <043D043618599C4017DE8774@utd59514.utdallas.edu> X-Enigmail-Version: 0.95.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: FreeBSD Questions Subject: Re: Shell scripting kungfu X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jan 2008 17:28:33 -0000 Paul Schmehl wrote: > I need to do the following: > > Take a list of various strings, one of which is a quoted IP address, and > extract the IPs. (Done that.) > > Then take the list of IPs and convert them to a list of IPs with masks > on a single line. > > IOW, I have converted the original list to this: > > x.x.x.x > x.x.x.x > x.x.x.x > x.x.x.x > > Now I need to remove the newlines and add /32, to the end of each IP so > that I have this: > x.x.x.x/32,x.x.x.x/32,x.x.x.x/32,etc. > > I got close with sed, but I'm not quite there. > > I got this: > > x.x.x.x/32,x.x.x.x > x.x.x.x/32,x.x.x.x > x.x.x.x/32,x.x.x.x > > Here's the code I used: > cat hostlist | cut -d',' -f2 | cut -d'"' -f2 | sort | uniq | grep -v > "inet" | sed '/[^*]$/N;s/\n */\/32,/' > > What am I missing? > Its a bit heavy to fireup but perl -pe 's/\n/\/32,/' hostlist should work (if you then remove the final tailing ,) Vince > >