From owner-freebsd-questions@FreeBSD.ORG Fri May 12 14:50:47 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 74AF316A56D for ; Fri, 12 May 2006 14:50:47 +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 E8F1343D6E for ; Fri, 12 May 2006 14:50:46 +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 k4CEokhn022089 for ; Fri, 12 May 2006 09:50:46 -0500 (CDT) (envelope-from martin@dc.cis.okstate.edu) Message-Id: <200605121450.k4CEokhn022089@dc.cis.okstate.edu> To: freebsd-questions@freebsd.org Date: Fri, 12 May 2006 09:50:46 -0500 From: Martin McCormick Subject: 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 14:50:48 -0000 This looks like something sed should be able to do, but I haven't had any luck at all. I wanted to remove any whitespace that has accidentally gotten added to the beginning or end of some lines of text. I made a test file that looks like: left justified. lots of spaces. and the best I have done so far is to get rid of about 3 spaces. Attempt 1. #! /usr/bin/sed -f s/ \+//g s/^ //g s/ $//g This looks like it should do the job, but the leading and trailing spaces are still mostly there. I wrote another script. Attempt 2. #! /bin/sh sed 's/^[[:space:]]//g' \ |sed 's/[[:space:]]$//g' If I cat the test file through this script, it also removes one or two spaces, but not all the leading and trailing whitespace I put there. I can write a program in C to do this, but is there a sed script or other native application in FreeBSD that can do this? Thank you. Martin McCormick WB5AGZ Stillwater, OK Systems Engineer OSU Information Technology Department Network Operations Group