[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Replacing text in multiple files
From: |
Paul Jarc |
Subject: |
Re: Replacing text in multiple files |
Date: |
Mon, 12 Nov 2001 16:58:29 -0500 |
User-agent: |
Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7 (i386-redhat-linux-gnu) |
Jim Meyering <address@hidden> wrote:
> You might want to limit the process to files that will
> actually be changed -- sometimes it's best not to update timestamps,
> and if you're making backups as this is, there's no point in making
> a .bak file if it's identical to the original:
>
> find . -type f -print0 | grep -l oldstr \
> | xargs -0 perl -pi.bak -e 's/oldstr/newstr/g'
One of us is misunderstanding grep's -l option. AIUI, -l means that
grep will process input normally, but will output only filenames where
matches are found. So it won't work here (even if filenames were
newline-terminated instead of null-terminated, which grep certainly
isn't expecting). Rather:
find. -type f -print0 | xargs -0 sh -c '
set "$0" ${1+"$@"}
for i do
grep -q oldstr "$i" && perl -pi.bak -e s/oldstr/newstr/g "$i"
done'
But if you're going to use Perl, you might as well do all of it in
Perl.
paul