#!/usr/bin/perl -w # # replace_in_tree replaces stringx by stringy in files from current directory # recursiveley and backups the original files to *.bak like # find . -type f | xargs -n 255 perl -pi.bak -e 's/string x/string y/g' # does. # # Author : Sascha Wuestemann # License: Artistic GPL # eMail : Sascha.Wuestemann@epost.de use strict; sub usage { print < replaces the string "to_be_replaced" with "replacement" from the current directory downwards the filetree in files matching filematcher, e.g. "*" or "*.html" example: replace_in_tree "Author: Bill Gates" "Author: Larry Wall" *.html EOF } sub exec_replace { open(GUN,"find . -name \"$ARGV[2]\" -type f | xargs -n 255 perl -pi.bak -e 's/$ARGV[0]/$ARGV[1]/g'|")|| die "can't execute shell commands:$!\n"; close(GUN)|| warn "couldn't close shell:$!\n"; } if (not $ARGV[2]) { usage; exit; } else { exec_replace } exit;