From owner-freebsd-questions@FreeBSD.ORG Thu Oct 13 03:50:18 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 03DA516A41F for ; Thu, 13 Oct 2005 03:50:18 +0000 (GMT) (envelope-from freebsd@philip.pjkh.com) Received: from wolf.pjkh.com (wolf.pjkh.com [66.228.196.74]) by mx1.FreeBSD.org (Postfix) with ESMTP id A27C343D49 for ; Thu, 13 Oct 2005 03:50:17 +0000 (GMT) (envelope-from freebsd@philip.pjkh.com) Received: from localhost (localhost [127.0.0.1]) by wolf.pjkh.com (Postfix) with ESMTP id E395117271; Wed, 12 Oct 2005 20:50:10 -0700 (PDT) Received: from wolf.pjkh.com ([127.0.0.1]) by localhost (wolf.pjkh.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 78160-09; Wed, 12 Oct 2005 20:50:10 -0700 (PDT) Received: by wolf.pjkh.com (Postfix, from userid 1000) id 825FF1726F; Wed, 12 Oct 2005 20:50:10 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by wolf.pjkh.com (Postfix) with ESMTP id 78E1E17083; Wed, 12 Oct 2005 20:50:10 -0700 (PDT) Date: Wed, 12 Oct 2005 20:50:10 -0700 (PDT) From: Philip Hallstrom To: Peter Matulis In-Reply-To: <20051013031521.5468.qmail@web60021.mail.yahoo.com> Message-ID: <20051012204909.J78693@wolf.pjkh.com> References: <20051013031521.5468.qmail@web60021.mail.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: amavisd-new at pjkh.com Cc: freebsd-questions 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 03:50:18 -0000 > Hi. I am writing up a doc for the fbsd community that covers usage of > ports. I have two commands that allow me to assertain the amount of > disk space being utilized by currently installed ports. I would like to > make a shell script (bourne or bash) out of them but I am not sure how. > > 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 //' ----------------------------------------------------