Re: Find and Replace text script?
by gellyfish (Monsignor) on Jul 13, 2006 at 18:49 UTC
|
find . -name '*.html' | xargs perl -pi -e 's/php\?/html/g'
?
/J\ | [reply] [d/l] |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Re: Find and Replace text script?
by Joost (Canon) on Jul 13, 2006 at 18:51 UTC
|
perl -i -pe 's/php\?/html/g' *
See perlrun
| [reply] [d/l] |
|
|
> perl -i -pe 's/php\?/html/g' *
Got it to work! :-)
Thank you!!
-Bob
| [reply] |
Re: Find and Replace text script?
by saberworks (Curate) on Jul 13, 2006 at 20:40 UTC
|
By php? do you mean you want to match php, php3, php4, phps, etc.? Or the literal string, 'php' followed by a literal question mark? | [reply] |
|
|
| [reply] |
|
|
| [reply] [d/l] |
|
|
Re: Find and Replace text script?
by duckyd (Hermit) on Jul 13, 2006 at 19:11 UTC
|
find . -type f -name '*.html' -exec perl -pi -e 's/php\?/html/g' {} \;
| [reply] [d/l] |
|
|
$ find . -maxdepth 1 | xargs perl -le 'print "$$: my args: @ARGV"'
12390: my args: . ./bash ./rbash ./sh ./cat ./chgrp ./chmod ./chown ./
+cp [...]
$ find . -maxdepth 1 -exec perl -le 'print "$$: my args: @ARGV"' {} \;
12399: my args: .
12400: my args: ./bash
12401: my args: ./rbash
12402: my args: ./sh
12403: my args: ./cat
12404: my args: ./chgrp
12405: my args: ./chmod
12406: my args: ./chown
12407: my args: ./cp
[...]
| [reply] [d/l] [select] |
|
|
Generally, I don't care if I'm spawning a new copy of perl or not. It runs plenty fast either way
| [reply] |
|
|
find . -type f -name '*.html' -exec perl -pi -e 's/php\?/html/g' {} \;
hmmm ... when I run this, my computer *sounds* like it's processing the files and after about thirty seconds it stops and prints a new Terminal line. However, when I go to check the files, they remain unchanged. Do I need to change this "find . -type f -name" part somehow?
Thanks,
-Bob
| [reply] [d/l] |
|
|
I am still unclear as to whether you're changing filenames from .php to .html, or changing all occurrences of the word "php?" to "html" within each file, or if you're trying to translate a PHP file to an HTML file (which doesn't really make sense, but the question really is ambiguous).
Honestly, what are you TRYING to do? Please explain clearly.
| [reply] |
|
|
|
|
Why avoid xargs? This is exactly the sort of thing this is for (or you may as well avoid find also and do the whole thing in perl).
| [reply] [d/l] |
|
|
sorry, just posted it in the spirit of TIMTOWTDI
| [reply] |