From owner-freebsd-questions@FreeBSD.ORG Wed Oct 7 10:26:52 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 1D1071065670 for ; Wed, 7 Oct 2009 10:26:52 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [IPv6:2a01:170:102f::2]) by mx1.freebsd.org (Postfix) with ESMTP id 912418FC08 for ; Wed, 7 Oct 2009 10:26:51 +0000 (UTC) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id n97AQZgw011099; Wed, 7 Oct 2009 12:26:50 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id n97AQYJw011098; Wed, 7 Oct 2009 12:26:34 +0200 (CEST) (envelope-from olli) Date: Wed, 7 Oct 2009 12:26:34 +0200 (CEST) Message-Id: <200910071026.n97AQYJw011098@lurza.secnetix.de> From: Oliver Fromme To: freebsd-questions@FreeBSD.ORG, the.real.david.allen@gmail.com In-Reply-To: <2daa8b4e0910062345r83fa23aj113b062af114887f@mail.gmail.com> X-Newsgroups: list.freebsd-questions User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Wed, 07 Oct 2009 12:26:50 +0200 (CEST) Cc: Subject: Re: A general sed question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-questions@FreeBSD.ORG, the.real.david.allen@gmail.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Oct 2009 10:26:52 -0000 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 > > - delete commented lines > - remove inline comments > - remove trailing spaces and/or tabs > - delete blank lines, and/or lines containing just spaces and/or tabs > - expand tabs I recommend to use the -Bb options of diff. They cause diff to ignore blank lines and any changes in the amount of white space (including tabs). You can also use -w to ignore *all* white space, but note that "foo bar" and "foobar" are then considered equal, which might not be what you want. So only the removal of comments remains: sed 's/#.*//' That will remove all comments. Afterwards, commented lines are empty, so the -B option of diff will ignore them, so you don't have to remove them explicitly. When using zsh as your shell, you can use a nice feature called "process substitution", so you don't have to create temporary files: diff -Buw <(sed 's/#.*//' GENERIC) <(sed 's/#.*//' MYKERNEL) I think bash has a similar feature, but I don't know the syntax, so please see the manpage if you're a bash user. If you need to do that oftem, it's worth to create an alias or shell function. Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd "People still program in C. People keep writing shell scripts. *Most* people don't realize the shortcomings of the tools they are using because they a) don't reflect on their workflows and they are b) too lazy to check out alternatives to realize there is help." -- Simon 'corecode' Schubert