From owner-freebsd-questions@FreeBSD.ORG Fri May 12 16:03:07 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 5A0C716A49A for ; Fri, 12 May 2006 16:03:07 +0000 (UTC) (envelope-from martin@dc.cis.okstate.edu) Received: from dc.cis.okstate.edu (dc.cis.okstate.edu [139.78.100.219]) by mx1.FreeBSD.org (Postfix) with ESMTP id DE63443D58 for ; Fri, 12 May 2006 16:03:06 +0000 (GMT) (envelope-from martin@dc.cis.okstate.edu) Received: from dc.cis.okstate.edu (localhost.cis.okstate.edu [127.0.0.1]) by dc.cis.okstate.edu (8.12.6/8.12.6) with ESMTP id k4CG36hn018673 for ; Fri, 12 May 2006 11:03:06 -0500 (CDT) (envelope-from martin@dc.cis.okstate.edu) Message-Id: <200605121603.k4CG36hn018673@dc.cis.okstate.edu> To: freebsd-questions@freebsd.org Date: Fri, 12 May 2006 11:03:06 -0500 From: Martin McCormick 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 16:03:07 -0000 Chuck Swiger quotes and writes: >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 ... That did it! As soon as I saw the *, I knew what I was not doing. >> 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. :-) Wow! I'd almost forgotten some of that by-gone era. I had a 1200-baud modem that, in conjunction with the clock slips between our local telephone company and our PBX, used to march [] and various other garbage characters that did look just like regex. You just had to keep re-dialing until you finally got a connection that worked. Thanks to everyone for the help. Martin McCormick WB5AGZ Stillwater, OK Systems Engineer OSU Information Technology Department Network Operations Group