From owner-freebsd-questions Fri May 31 5:17:47 2002 Delivered-To: freebsd-questions@freebsd.org Received: from bisclavret.iris33.ac-bordeaux.fr (0332832Z-nat1.ac-bordeaux.fr [194.199.34.67]) by hub.freebsd.org (Postfix) with ESMTP id 798F537B404 for ; Fri, 31 May 2002 05:17:42 -0700 (PDT) Received: (from benoit@localhost) by bisclavret.iris33.ac-bordeaux.fr (8.11.3/8.11.1) id g4VCELP72133; Fri, 31 May 2002 14:14:21 +0200 (CEST) (envelope-from benoit) Date: Fri, 31 May 2002 14:14:21 +0200 From: Benoit Lacherez To: j mckitrick Cc: freebsd-questions@freebsd.org Subject: Re: Why does 'sed' delete my input file? Message-ID: <20020531141421.A72043@bisclavret.iris33.ac-bordeaux.f> References: <20020531130029.B28925@dogma.freebsd-uk.eu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5i In-Reply-To: <20020531130029.B28925@dogma.freebsd-uk.eu.org>; from jcm@FreeBSD-uk.eu.org on Fri, May 31, 2002 at 01:00:29PM +0100 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG j mckitrick a écrit : > > This is a simple question, but I can't find the answer. The Daemonnews > article that seems to answer it is missing the graphics with the > screenshots. > > If I want to replace all occurrences of 'foo' in a file, this is what I > tried: > > sed s/foo/bar/g file1 > file1 > > But this deletes (overwrites?) the contents of the file. What did I do > wrong? If you redirect your command output to file1, this file is first opened in write mode (and so cleared) then opened in read mode, but at that time, it's already empty... The solution is to read the file first, then to write in it : cat file1 | sed 's/foo/bar/g' > file1 -- Benoit Lacherez Académie de Bordeaux -- CATICE Projet de traduction de la documentation de Python: http://frpython.sourceforge.net/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message