From owner-freebsd-questions@FreeBSD.ORG Thu Jul 10 11:27:00 2003 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 79FD837B401 for ; Thu, 10 Jul 2003 11:27:00 -0700 (PDT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id CB02743FAF for ; Thu, 10 Jul 2003 11:26:59 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.9/8.12.9) id h6AIQxd7016492; Thu, 10 Jul 2003 13:26:59 -0500 (CDT) (envelope-from dan) Date: Thu, 10 Jul 2003 13:26:59 -0500 From: Dan Nelson To: "Jack L. Stone" Message-ID: <20030710182658.GC49845@dan.emsphone.com> References: <3.0.5.32.20030710123009.0135fe88@sage-one.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3.0.5.32.20030710123009.0135fe88@sage-one.net> X-OS: FreeBSD 5.1-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.4i cc: freebsd-questions@freebsd.org Subject: Re: Replacing string in multiple files 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: Thu, 10 Jul 2003 18:27:00 -0000 In the last episode (Jul 10), Jack L. Stone said: > Am running FBSD.4.8-R > > At times, I need to replace an existing string in a file that has the same > name in all ~user accounts and know there must be a short script to do that > and suspect it involves sed(1). However, had no luck getting it to work > yet. Basically want to do this: > > - find same files in all ~users by same name "~users/myfile" > - replace this ${string} with this ${string} in the above files > - report list of above files modified successfully If all your users share a common hierarchy: sed -i.bak -e s/oldstring/newstring/ /home/*/myfile You'll need to be running FreeBSD 4.7 or newer for sed -i to work. Not sure how to get a list of changed files, though. Maybe just do a grep beforehand? -- Dan Nelson dnelson@allantgroup.com