From owner-freebsd-questions@FreeBSD.ORG Fri Jan 18 17:09:14 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 C464B16A41A for ; Fri, 18 Jan 2008 17:09:14 +0000 (UTC) (envelope-from pauls@utdallas.edu) Received: from smtp3.utdallas.edu (smtp3.utdallas.edu [129.110.10.49]) by mx1.freebsd.org (Postfix) with ESMTP id 92A3313C4CC for ; Fri, 18 Jan 2008 17:09:14 +0000 (UTC) (envelope-from pauls@utdallas.edu) Received: from utd59514.utdallas.edu (utd59514.utdallas.edu [129.110.3.28]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp3.utdallas.edu (Postfix) with ESMTP id 3C8376550F for ; Fri, 18 Jan 2008 11:09:14 -0600 (CST) Date: Fri, 18 Jan 2008 11:09:14 -0600 From: Paul Schmehl To: FreeBSD Questions Message-ID: <043D043618599C4017DE8774@utd59514.utdallas.edu> X-Mailer: Mulberry/4.0.8 (Linux/x86) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: 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:09:14 -0000 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? -- Paul Schmehl (pauls@utdallas.edu) Senior Information Security Analyst The University of Texas at Dallas http://www.utdallas.edu/ir/security/