From owner-freebsd-questions@FreeBSD.ORG Thu Oct 13 06:36:41 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 28A1416A434 for ; Thu, 13 Oct 2005 06:36:41 +0000 (GMT) (envelope-from petermatulis@yahoo.ca) Received: from web60012.mail.yahoo.com (web60012.mail.yahoo.com [209.73.178.75]) by mx1.FreeBSD.org (Postfix) with SMTP id 8883743D49 for ; Thu, 13 Oct 2005 06:36:40 +0000 (GMT) (envelope-from petermatulis@yahoo.ca) Received: (qmail 25208 invoked by uid 60001); 13 Oct 2005 06:36:36 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.ca; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=0oH4qXggUY7OjveJ2zXlVJVa6P0q6yAtxZVevivcGiV9YYG1OXFKhE606A7MZap8o1lbRHE8ZkeND92YAURZw54PVO1ZA6FExYqk2+r8a4GUEW1hUs08hO86OceRclC9ka6k2sJHtfcSL+LXGC8+2msztQXJ1ePW13dZlz+EENc= ; Message-ID: <20051013063636.25206.qmail@web60012.mail.yahoo.com> Received: from [216.252.84.150] by web60012.mail.yahoo.com via HTTP; Thu, 13 Oct 2005 02:36:36 EDT Date: Thu, 13 Oct 2005 02:36:36 -0400 (EDT) From: Peter Matulis To: freebsd-questions In-Reply-To: <20051013053543.51718.qmail@web60016.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: help with shell script 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: Thu, 13 Oct 2005 06:36:41 -0000 --- Peter Matulis wrote: > > --- Philip Hallstrom wrote: > > > > 1. This gives me the amount of space (kB) taken up by the 10 largest ports: > > > > > > $ pkg_info -as | grep ^[0-9] | sort -gr | head -10 | cut -c 1-6 > > > > > > 2. Using one figure from above list I produce the details of the corresponding port: > > > > > > $ pkg_info -as | grep -B3 240695 > > > > > > Output: > > > ------------------------------------------------------ > > > Information for linux_base-8-8.0_6: > > > > > > Package Size: > > > 240695 (1K-blocks) > > > ------------------------------------------------------ > > > > > > I would like the output of the script to be the above but for all ten ports (~40 lines; > > insert > > > a blank line between each?). I know I need some sort of iteration but I am rusty on > > scripting. > > > Can anyone help? > > > > This should get you close... if you want only the top 10 just add more > > pipes to the end with sort and head... > > > > ---------------------------------------------------- > > #!/bin/sh > > > > newline='\ > > ' > > > > pkg_info -as | \ > > tr '\n' ' ' | \ > > sed -e 's/Package Size://g' \ > > -e "s/(1K-blocks)/$newline/g" |\ > > sed -e 's/^ *Information for //' > > ---------------------------------------------------- > > What I need is the size as the first item (not the second) on each line. Then I can use > sort. Allrighty, I employed some awk to get a good enough output: ---------------------------------------------------- #!/bin/sh newline='\ ' pkg_info -as | \ tr '\n' ' ' | \ sed -e 's/Package Size://g' \ -e "s/(1K-blocks)/$newline/g" | \ tr ':' ' ' | \ awk '{print$4," ",$3}' | \ sort -gr | \ head -30 ---------------------------------------------------- Thanks. __________________________________________________________ Find your next car at http://autos.yahoo.ca