From owner-freebsd-questions@FreeBSD.ORG Wed Jan 26 15:54:32 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 D801616A4CE for ; Wed, 26 Jan 2005 15:54:32 +0000 (GMT) Received: from mail28.sea5.speakeasy.net (mail28.sea5.speakeasy.net [69.17.117.30]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7CCB743D46 for ; Wed, 26 Jan 2005 15:54:32 +0000 (GMT) (envelope-from freebsd-questions-local@be-well.ilk.org) Received: (qmail 9637 invoked from network); 26 Jan 2005 15:54:31 -0000 Received: from dsl092-078-145.bos1.dsl.speakeasy.net (HELO be-well.ilk.org) ([66.92.78.145]) (envelope-sender ) by mail28.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 26 Jan 2005 15:54:31 -0000 Received: by be-well.ilk.org (Postfix, from userid 1147) id 6F08B84; Wed, 26 Jan 2005 10:54:30 -0500 (EST) Sender: lowell@be-well.ilk.org To: freebsd-questions@freebsd.org To: Anthony Atkielski References: <1878149195.20050126164325@wanadoo.fr> From: Lowell Gilbert Date: 26 Jan 2005 10:54:30 -0500 In-Reply-To: <1878149195.20050126164325@wanadoo.fr> Message-ID: <44r7k82nk9.fsf@be-well.ilk.org> Lines: 22 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 Reply-To: freebsd-questions@freebsd.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jan 2005 15:54:33 -0000 Anthony Atkielski writes: > 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? You should be able to figure this out pretty quickly on your own from the manual, but I'll do your homework for you... find . -type f -exec sed -i "" -e "s/e/E/g" {} \; [changes every lower-case e to upper-case in all regular files in this directory and all directories "below" it] [There are several other ways to do it, too, in about the same amount of typing. In particular, using xargs(1) instead of -exec could make it run faster if you have large numbers of files.]