in reply to Find and Replace text script?

avoiding xargs:
find . -type f -name '*.html' -exec perl -pi -e 's/php\?/html/g' {} \;

Replies are listed 'Best First'.
(OT) Re^2: Find and Replace text script?
by Hue-Bond (Priest) on Jul 13, 2006 at 19:41 UTC
    avoiding xargs

    Why spawn a copy of perl for each file?

    $ 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 [...]

    --
    David Serrano

      Generally, I don't care if I'm spawning a new copy of perl or not. It runs plenty fast either way
Re^2: Find and Replace text script?
by bobafifi (Beadle) on Jul 13, 2006 at 19:46 UTC
    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

      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.


      Dave

        > Honestly, what are you TRYING to do? Please explain clearly.

        Sorry for the confusion Dave ... I thought I had ...
        "the file names have already been changed to .html using Automator, so don't need that done"

        > or changing all occurrences of the word "php?" to "html" within each file

        yes - that's what I'm trying to do.

        Thanks,

        -Bob

Re^2: Find and Replace text script?
by runrig (Abbot) on Jul 13, 2006 at 19:52 UTC
    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).
      sorry, just posted it in the spirit of TIMTOWTDI