Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Jan 2005 06:07:59 +0000
From:      markzero <mark@darklogik.org>
To:        freebsd-questions@freebsd.org
Subject:   Re: One-line global string replace in all files with sed (or awk?)
Message-ID:  <20050128060759.GA9405@logik.ath.cx>
In-Reply-To: <1098984237.20050128065616@wanadoo.fr>
References:  <1098984237.20050128065616@wanadoo.fr>

next in thread | previous in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050128060759.GA9405>