in reply to Re: RE: Replace across files (extreme newbie)
in thread Replace across files (extreme newbie)
If you want to put a complex shell command in a script, use a shell script, that's what it was made for.
If you just want to execute a shell command in a perl script, use the system command. Unless you need the output of the command, then use backticks.
Here is an example of a shell script doing the same as your perl script, but with much less resources:
Update: I forgot to mention that your script will probably fail.#!/bin/sh if [ $# -lt 3 ]; then echo " usage: replace_in_tree <to_be_replaced> <replacement> '<filematcher>' 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' " exit fi find . -name "$3" -type f | xargs -n 255 perl -pi.bak -e 's/\Q$1\E/$2/ +g'
|
|---|