I had a bunch of files, some of them binary, that needed to have a text replaced in all of them.
Here's the code that worked for me. It's a one liner, though quite a long line. I also launched it from a Linux shell.
find . -type f | /usr/bin/perl -e 'use feature ":5.12"; use File::Slur +p; for (<STDIN>) { chomp; $a = read_file ( $_, { binmode => ":raw" } +); $a =~ s/<div>Comments<\/div>/<div class="red">Comments<\/div>/g; w +rite_file ($_, { binmode => ":raw" }, $a); }'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replacing text in many files, including binaries
by FunkyMonk (Bishop) on Jun 02, 2011 at 15:30 UTC | |
|
Re: Replacing text in many files, including binaries
by jwkrahn (Abbot) on Jun 02, 2011 at 22:30 UTC | |
|
Re: Replacing text in many files, including binaries
by xenu (Novice) on Jun 05, 2011 at 15:00 UTC | |
|
Re: Replacing text in many files, including binaries
by mrdvt92 (Acolyte) on Jul 19, 2011 at 04:10 UTC | |
by jdporter (Paladin) on Jul 19, 2011 at 14:00 UTC |