From owner-freebsd-questions@FreeBSD.ORG Tue Jun 29 20:06:05 2004 Return-Path: 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 A821D16A4D8 for ; Tue, 29 Jun 2004 20:06:05 +0000 (GMT) Received: from clunix.cl.msu.edu (clunix.cl.msu.edu [35.9.2.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8907243D4C for ; Tue, 29 Jun 2004 20:06:00 +0000 (GMT) (envelope-from jerrymc@clunix.cl.msu.edu) Received: (from jerrymc@localhost) by clunix.cl.msu.edu (8.11.7p1+Sun/8.11.7) id i5TK5nZ18158; Tue, 29 Jun 2004 16:05:49 -0400 (EDT) From: Jerry McAllister Message-Id: <200406292005.i5TK5nZ18158@clunix.cl.msu.edu> To: fbsd-questions@trini0.org (Gerard Samuel) Date: Tue, 29 Jun 2004 16:04:02 -0400 (EDT) In-Reply-To: <200406291545.40422.fbsd-questions@trini0.org> from "Gerard Samuel" at Jun 29, 2004 03:45:40 PM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit cc: freebsd-questions@freebsd.org cc: Bill Moran Subject: Re: Means of trimming files X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Jun 2004 20:06:05 -0000 > > On Tuesday 29 June 2004 01:07 pm, Bill Moran wrote: > > Gerard Samuel wrote: > > > When editing php files, via the command line, there is a newline > > > character after the closing ?> > > > Im looking for a command that would trim files, so that I can append it > > > to the find command. > > > > > > find ./ -name '*.php' -exec SOME_COMMAND {} \; > > > > If you're absolutely sure of the number of characters you're removing from > > the end of the file, you could use truncate(1). > > > > Otherwise, you'll probably want sed or perl to check that it's not removing > > important characters. > > Trying to use truncate is not working on my end. > Does anyone see a syntax error with it??? > Ran on 5.2.1-RELEASE-p6 FreeBSD. > > $ pwd > /usr/home/gsam > $ ls ~/z.php > /home/gsam/z.php > $ truncate -r ~/z.php > usage: truncate [-c] -s [+|-]size[K|M|G] file ... > truncate [-c] -r rfile file ... > > I tried $ truncate -r rfile ~/z.php but that didn't work either. Well is 'rfile' the exact length you want and is it always going to be exactly a newline character shorter than z.php? Maybe you want something more like 'truncate -s -1 z.php' presuming it is always just one newline character at the end. Do you need to take the character only from the last line of the file or from any line in the file that has it? If it is from any line, check out tr(1). tr -d "\n" < z.php > z.php-clean rm z.php mv z.php-clean z.php Otherwise, I would be inclined to break out perl. ////jerry > Thanks