From owner-freebsd-questions@FreeBSD.ORG Thu Oct 8 00:56:38 2009 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 039C810656BD for ; Thu, 8 Oct 2009 00:56:38 +0000 (UTC) (envelope-from freebsd@optimis.net) Received: from mail.optimis.net (mail.optimis.net [69.104.191.124]) by mx1.freebsd.org (Postfix) with ESMTP id C756C8FC1A for ; Thu, 8 Oct 2009 00:56:37 +0000 (UTC) Received: from marvin.optimis.net (marvin.optimis.net [192.168.1.3]) by mail.optimis.net (8.14.3/8.14.2) with ESMTP id n980ubGP001161 for ; Wed, 7 Oct 2009 17:56:37 -0700 (PDT) (envelope-from freebsd@optimis.net) Received: from marvin.optimis.net (localhost [127.0.0.1]) by marvin.optimis.net (8.14.3/8.14.3) with ESMTP id n980uaMV039885 for ; Wed, 7 Oct 2009 17:56:36 -0700 (PDT) (envelope-from freebsd@optimis.net) Received: (from george@localhost) by marvin.optimis.net (8.14.3/8.14.3/Submit) id n980uanZ039884 for freebsd-questions@freebsd.org; Wed, 7 Oct 2009 17:56:36 -0700 (PDT) (envelope-from freebsd@optimis.net) Date: Wed, 7 Oct 2009 17:56:36 -0700 From: George Davidovich To: freebsd-questions@freebsd.org Message-ID: <20091008005636.GA38899@marvin.optimis.net> References: <2daa8b4e0910062345r83fa23aj113b062af114887f@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2daa8b4e0910062345r83fa23aj113b062af114887f@mail.gmail.com> User-Agent: Mutt/1.5.19 (2009-01-05) Subject: Re: A general sed question 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, 08 Oct 2009 00:56:38 -0000 On Tue, Oct 06, 2009 at 11:45:36PM -0700, David Allen wrote: > I keep bumping up against this, so I thought I'd throw this question out > to those who understand sed better than I do. > > What I'm trying to do is to clean up the contents of some files > (/sys/i386/conf/GENERIC would be a good example) to get more readable > diffs. To that end, I'm trying to use sed to For the following note that what's contained in the square brackets is a space character followed by a literal TAB character (typically created by entering ^V followed by TAB). > - delete commented lines > - remove inline comments s/[ ]*#.*// # takes care of both, but will leave \t\t\t\n > - remove trailing spaces and/or tabs s/[ ]*$// # handy, but not needed if using diff -b > - delete blank lines, and/or lines containing just spaces and/or tabs /^[ ]*$/d > - expand tabs This is overly complex with sed and probably unecessary. Instead I'd suggest using your editor (in vim, it's ':set expandtab | retab'), or for interactive use, relying on expand(1) and using a value for -t that matches the tab spacing you typically use for your pager and/or editor. Alternatively, to get better visual alignment when using diff(1), just use the -t option. Putting the above together, you get sed -e 's/[ ]*#.*//' -e 's/[ ]*$//' -e '/^[ ]*$/d' Hardly ideal but it's readable enough and satisfies the 80/20 rule. If used as a simple alias, shell function or script as Oliver Fromme suggested (yes, this works in bash), my suggestion is diff -ubBt <(cleanup /sys/i386/conf/GENERIC) <(cleanup /path/to/NEWKERNEL) -- George