From owner-freebsd-questions Fri May 31 5:21: 1 2002 Delivered-To: freebsd-questions@freebsd.org Received: from dns.perimeter.co.za (dns.perimeter.co.za [196.25.164.254]) by hub.freebsd.org (Postfix) with ESMTP id 2C55E37B403 for ; Fri, 31 May 2002 05:20:52 -0700 (PDT) Received: from PATRICK (loopback.mipjhb [209.212.102.245] (may be forged)) by dns.perimeter.co.za (8.11.1/8.11.1) with SMTP id g4VCIl101196; Fri, 31 May 2002 14:18:48 +0200 (SAST) (envelope-from bsd@perimeter.co.za) Message-ID: <028601c2089c$fd7eef30$b50d030a@PATRICK> From: "Patrick O'Reilly" To: "j mckitrick" Cc: References: <20020531130029.B28925@dogma.freebsd-uk.eu.org> Subject: Re: Why does 'sed' delete my input file? Date: Fri, 31 May 2002 14:16:21 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 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 ----- Original Message ----- From: "j mckitrick" > 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? > The shell will open the file for output first (thereby emptying it). Try this: # sed s/foo/bar/g file1 > /tmp/x && mv /tmp/x file1 Regards, Patrick O'Reilly. ___ _ __ / _ )__ __ (_)_ __ ___ _/ /____ __ / __/ -_) _) / ~ ) -_), ,-/ -_) _) /_/ \__/_//_/_/~/_/\__/ \__/\__/_/ http://www.perimeter.co.za To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message