From owner-freebsd-questions@FreeBSD.ORG Fri Dec 18 16:38:22 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 AEFEB106568D for ; Fri, 18 Dec 2009 16:38:22 +0000 (UTC) (envelope-from nb@ravenbrook.com) Received: from raven.ravenbrook.com (raven.ravenbrook.com [193.164.110.8]) by mx1.freebsd.org (Postfix) with ESMTP id 243DF8FC08 for ; Fri, 18 Dec 2009 16:38:21 +0000 (UTC) Received: from thrush.ravenbrook.com (thrush.ravenbrook.com [193.164.110.145]) by raven.ravenbrook.com (8.14.3/8.14.2) with ESMTP id nBIGcGfb044976; Fri, 18 Dec 2009 16:38:16 GMT (envelope-from nb@ravenbrook.com) Received: from thrush.ravenbrook.com (localhost [127.0.0.1]) by thrush.ravenbrook.com (8.13.4/8.13.4) with ESMTP id nBIGcGq8012054; Fri, 18 Dec 2009 16:38:16 GMT (envelope-from nb@thrush.ravenbrook.com) From: Nick Barnes To: Warren Block In-Reply-To: from Warren Block of "Fri, 18 Dec 2009 09:33:49 -0700" Date: Fri, 18 Dec 2009 16:38:16 +0000 Message-ID: <12053.1261154296@thrush.ravenbrook.com> Sender: nb@ravenbrook.com X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.3 (raven.ravenbrook.com [193.164.110.8]); Fri, 18 Dec 2009 16:38:16 +0000 (GMT) X-Virus-Scanned: ClamAV 0.94.1/10198/Fri Dec 18 15:19:17 2009 on raven.ravenbrook.com X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on raven.ravenbrook.com X-Spam-Level: X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Cc: glarkin@freebsd.org, mexas@bristol.ac.uk, perryh@pluto.rain.com, freebsd-questions@freebsd.org Subject: Re: editing a binary file 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, 18 Dec 2009 16:38:22 -0000 At 2009-12-18 16:33:49+0000, Warren Block writes: > perryh@pluto.rain.com wrote: > > Greg Larkin wrote: > > > ... > > > > truncate -4 myfile should get rid of the last four bytes. Maybe > > > > there's a similar efficient way to truncate the start of a file. > > > > > > This should do it: > > > > > > dd if=oldfile of=newfile bs=1 skip=4 > > > > Or, perhaps marginally more efficient: > > > > dd if=oldfile of=newfile bs=4 skip=1 > > It would be nice to avoid the file copy, but maybe there's no way to do > that. The small buffer size for dd will probably make copies of > multi-gig files slow. This might be faster: > > tail -c +5 myfile > outfile > truncate -4 outfile > > (Has anyone mentioned that you can edit binary files interactively with > vi yet? No? Well, it's horrific and surely has interesting failure > modes. And there are probably disadvantages also.) All very interesting, but the OP is wanting to lose all the Fortran record markers, not just the first (and last) four bytes of the file. The record markers precede and follow each record, and give the record's length. The size and enddian-ness of the record marker itself depends on the Fortran implementation. Nick B