From owner-freebsd-questions@FreeBSD.ORG Fri Jan 28 06:07:54 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 25BD716A4CE for ; Fri, 28 Jan 2005 06:07:54 +0000 (GMT) Received: from addr14.addr.com (addr14.addr.com [209.249.147.92]) by mx1.FreeBSD.org (Postfix) with ESMTP id DEAED43D39 for ; Fri, 28 Jan 2005 06:07:53 +0000 (GMT) (envelope-from markzero@logik.ath.cx) Received: from logik.ath.cx (localhost [127.0.0.1])j0S67pUB010192 for ; Thu, 27 Jan 2005 22:07:51 -0800 (PST) Received: by logik.ath.cx (Postfix, from userid 1001) id E019B61A9; Fri, 28 Jan 2005 06:07:59 +0000 (UTC) Date: Fri, 28 Jan 2005 06:07:59 +0000 From: markzero To: freebsd-questions@freebsd.org Message-ID: <20050128060759.GA9405@logik.ath.cx> References: <1098984237.20050128065616@wanadoo.fr> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="tThc/1wpZn/ma/RB" Content-Disposition: inline In-Reply-To: <1098984237.20050128065616@wanadoo.fr> X-OS: FreeBSD 5.3-RELEASE-p5 i386 LOGIK005 X-GPG-Key: http://darklogik.org/pub/pgp/pgp.txt X-Fingerprint: B776 43DC 8A5D EAF9 2126 9A67 A7DA 390F DEFF 9DD1 User-Agent: Mutt/1.5.6i X-ADDRSpamFilter: Passed, probability (0%) X-ADDRSignature: 1F6D580B 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: Fri, 28 Jan 2005 06:07:54 -0000 --tThc/1wpZn/ma/RB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > My thanks to all who replied. I ended up using this form (I don't > recall who suggested it): >=20 > find . -type f | xargs sed -i '' -e 's/foo/bar/g' >=20 > One problem, though: It appears that sed touches every file, resetting > the last modification time, even if it didn't actually change anything. > This reset the last modification dates for every file on my site, which > wasn't much fun. Is there another command I could put between find and > xargs that would filter only the names of files containing the string? > (grep would do it, but grep outputs the lines found to stdout, so that > won't do.) >=20 Completely off the top of my head: #!/bin/sh =20 for i in `find $PWD -type f`; =20 do grep foo $i 1>/dev/null; if [ $? -ne 0 ] then #do something with sed here fi done; Not *exactly* a one liner but it *could* be if you want to make it less readable... :) Mark --=20 PGP: http://www.darklogik.org/pub/pgp/pgp.txt B776 43DC 8A5D EAF9 2126 9A67 A7DA 390F DEFF 9DD1 --tThc/1wpZn/ma/RB Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (FreeBSD) iQIVAwUBQfnWvqfaOQ/e/53RAQIjjQ/+L8WLCjks1x/mk/RmyJ/82P/FKRwuoV25 5NK9O7xhFZW2bwVDpA9lIGOuTthSUQPVg7uhpGTs4FNGLk07MaKAGUX5JphtXIlf sY9ceY1Z8q/RRTxc59AgnhC+0WmTZmf55PBzhX2ApfNou4gRd/p3ehxJEwyhQ4Nh 862mCKalAib47QEqtg9IsyaRpG0tIkUs6Q/IA/taVq9wEuLFMs1ivyYg4FLg5yA4 pE9f3Na1+lAxERCFjgI1nNystbR001v+PiwoMvdKedRIR4IqI0JTJ6iUC1OVaQnc W2h0sVcUO2ItVBOaRjO6SoD0x0iahpf2IuZ317B28h8Vr1ktdvX4DYxJGc5YwskV 8KOBeGgG2/yF0MHLMfcLIRUNH89Xoy+nukrfiZIv/m1qf/n/YfvDq+wnUSAMvKQY LxazWcN4/mzOYEicKVP9YE/m7JtdrJMeiCcMxkACvYW/ImF1Qj9rh1wJZTn42jPj AfiQt1tSkDRUaKW+rxLakACglqFEBBPZ9HkPlEJEgGhfUTRS5iS+4SPy7/Ffp496 S6bVLtRsTxdF4MPwXhfclg3HhsMcFoBTOViYd57/rYi3tWx94JCwrw/s+seRM56k jcsD4WBw9Z8XEjeVTWunIeLalbyMMZ+yGOY1+XQrfDA/hM/aQGssiC2MlB1oPI/O 3LaqDdIniNA= =hYSH -----END PGP SIGNATURE----- --tThc/1wpZn/ma/RB--