From owner-freebsd-questions@FreeBSD.ORG Fri May 12 15:27:12 2006 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 BD0F316A74E for ; Fri, 12 May 2006 15:27:12 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from pi.codefab.com (pi.codefab.com [199.103.21.227]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0F66643D45 for ; Fri, 12 May 2006 15:27:12 +0000 (GMT) (envelope-from cswiger@mac.com) Received: from localhost (localhost [127.0.0.1]) by pi.codefab.com (Postfix) with ESMTP id 6FB0F5CBF; Fri, 12 May 2006 11:27:11 -0400 (EDT) X-Virus-Scanned: amavisd-new at codefab.com Received: from pi.codefab.com ([127.0.0.1]) by localhost (pi.codefab.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hlf6kkUcnu3B; Fri, 12 May 2006 11:27:10 -0400 (EDT) Received: from [192.168.1.251] (pool-68-160-235-217.ny325.east.verizon.net [68.160.235.217]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pi.codefab.com (Postfix) with ESMTP id 845B45C75; Fri, 12 May 2006 11:27:10 -0400 (EDT) Message-ID: <4464A94C.6020606@mac.com> Date: Fri, 12 May 2006 11:27:08 -0400 From: Chuck Swiger User-Agent: Thunderbird 1.5.0.2 (Windows/20060308) MIME-Version: 1.0 To: Giorgos Keramidas References: <200605121450.k4CEokhn022089@dc.cis.okstate.edu> <20060512150608.GB25497@gothmog.pc> In-Reply-To: <20060512150608.GB25497@gothmog.pc> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Martin McCormick , freebsd-questions@freebsd.org Subject: Re: Trimming Whitespace From Beginning and end of Text Lines 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, 12 May 2006 15:27:14 -0000 Giorgos Keramidas wrote: > This fails to remove multiple occurences of the [[:space:]] class. > > There are at least the following ways: > > sed -i -e 's/^[[:space:]]*' -e 's/[[:space:]]*$//' file ... > perl -pi -e 's/^\s*(\S.*\S)[ \t]*$/$1/' file ... > > The first one seems more straightforward to me most of the time, > but there are times I find Perl's `-pi -e ...' idiom very convenient. > It is, and I wish to acknowledge the above are entirely valid solutions to the problem, but... python -c 'import sys; print sys.stdin.read().strip()' < file... ...has the advantage of being human readable. My old 300-baud accoustic modem used to generate output which in hindsight looks astonishingly close to regex character classes. :-) -- -Chuck