From owner-freebsd-questions@FreeBSD.ORG Fri Dec 18 18:02:49 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 84D731065670 for ; Fri, 18 Dec 2009 18:02:49 +0000 (UTC) (envelope-from ocean_ieee@yahoo.it) Received: from smtp103.plus.mail.re1.yahoo.com (smtp103.plus.mail.re1.yahoo.com [69.147.102.66]) by mx1.freebsd.org (Postfix) with SMTP id 22EAD8FC18 for ; Fri, 18 Dec 2009 18:02:48 +0000 (UTC) Received: (qmail 40252 invoked from network); 18 Dec 2009 18:02:48 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.it; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=aQRCJR7BZgKR1D/yjKuCYiNLhLH9SFGu/NMOK3APcTmnpbTBjiL8QNXQaLhoN1tAOJlY7eQkul4XwAhcSydVaUk+PmUJ/veWoY626KAqDsj0PF0KKaMwqNXg6BgK4RtI2o51NzaXhLwnhspFkx28OEAfI+G5XlXc4JSG4TPzf6s= ; Received: from 213-156-35-243.ip.fastwebnet.it (ocean_ieee@213.156.35.243 with plain) by smtp103.plus.mail.re1.yahoo.com with SMTP; 18 Dec 2009 10:02:48 -0800 PST X-Yahoo-SMTP: SYX_4.SswBCj2Fjsw.Apnvidq06mcRQ- X-YMail-OSG: DDbLu64VM1kbiCHXvYekf1z7T3Mu21EM2upUSx777thaWxn6f69XHPFpIicbHlXmBppNRIwYmm6LrguWGiEnhOoex5IvHzsU4lWkH3T_G.dapsaFWXwIoogv_f91DItPCslPcJtEOk2IIWskZLkhzV05DQOvmHlU9f.bkL6aLOE5fJBSaiOsaHpZWnQrK7QOSsuGJ3378GddXU_r2SvNXn1.FXf.UzZvwUdTBs12_W4.xu62SK.VtYI9pA8XKFsu1iVk6Vn6fImkLalMExuz.DV8dW8x.LB8lJg.pBUGO8WdwBHCXRo8I8Rhp1CWwnvtu8BAsRJwTfUO3IUjqFyDyA2t8hilaJ71X.PoVUcMPBxx0.DWHyVL7GULz79Bo.Ut_m3dhQJv2M2jZRHZLPBqzE1MGwH7PQ-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <4B2BC389.7040106@yahoo.it> Date: Fri, 18 Dec 2009 19:01:45 +0100 From: ocean User-Agent: Thunderbird 2.0.0.23 (X11/20091213) MIME-Version: 1.0 To: Anton Shterenlikht References: <20091218165627.GB89667@mech-cluster241.men.bris.ac.uk> In-Reply-To: <20091218165627.GB89667@mech-cluster241.men.bris.ac.uk> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: glarkin@freebsd.org, 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 18:02:49 -0000 Anton Shterenlikht wrote: > On Fri, Dec 18, 2009 at 09:33:49AM -0700, Warren Block wrote: >> 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.) > > Vim, yes. I tried, but failed. At the moment dd/truncate combination > seems the most appealing. But I'll look at C/perl/python proposed > solutions as well. > > many thanks >