From owner-freebsd-questions@FreeBSD.ORG Wed Jan 26 18:14:11 2005 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 76B8F16A4CE for ; Wed, 26 Jan 2005 18:14:11 +0000 (GMT) Received: from aiolos.otenet.gr (aiolos.otenet.gr [195.170.0.23]) by mx1.FreeBSD.org (Postfix) with ESMTP id B89E443D49 for ; Wed, 26 Jan 2005 18:14:05 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from orion.daedalusnetworks.priv (aris.bedc.ondsl.gr [62.103.39.226])j0QIDx84030275; Wed, 26 Jan 2005 20:14:00 +0200 Received: by orion.daedalusnetworks.priv (Postfix, from userid 1001) id 9BA0E2A42F; Wed, 26 Jan 2005 20:13:56 +0200 (EET) Date: Wed, 26 Jan 2005 20:13:56 +0200 From: Giorgos Keramidas To: Miguel Mendez Message-ID: <20050126181356.GA6596@orion.daedalusnetworks.priv> References: <1878149195.20050126164325@wanadoo.fr> <20050126165505.06d2b3d4.flynn@energyhq.es.eu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050126165505.06d2b3d4.flynn@energyhq.es.eu.org> cc: freebsd-questions@freebsd.org cc: atkielski.anthony@wanadoo.fr Subject: Re: One-line global string replace in all files with sed (or awk?) 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: Wed, 26 Jan 2005 18:14:11 -0000 On 2005-01-26 16:55, Miguel Mendez wrote: > On Wed, 26 Jan 2005 16:43:25 +0100 > Anthony Atkielski wrote: >> A few years ago, I'm sure I came across a one-line way of replacing >> every occurence of one string with another in an entire directory of >> files (potentially including all subdirectories as well). I think it >> used sed or awk. Now I can't find it. The examples on the Web are all >> multiline scripts or programs, but I'm sure I saw a way to do it all on >> just one line. >> >> Can anyone tell me how to do this? > > How about something like this (sh style)... > > for i in `find . -type f`; do sed -i -e 's/string1/string2/g' $i; done Nope. This will potentially overflow the command line limit of some shells and fail. The best way I know is to use find/xargs/sed: find . -type f | xargs sed -i '' -e 's/foo/bar/g'