[Novalug] perl help | filename spaces
lug-user at drmikehenry.com
Thu Mar 18 06:27:46 EDT 2010
On 03/17/2010 09:31 PM, Richard Barnes wrote:
> One solution here (kind of a hack):
> With that, it would be:
> find . -type f | while read FILE; do perl -e "s/news.html/news\//g;"
> -pi.save "$FILE" ; done
> Not quite as snappy, but it seems to work for me.
It handles filenames with spaces, but it will fall over if you
encounter files with newlines (for example). The link you
posted has a large number of comments about this issue, with a
lot of misunderstanding going on. There are good reasons to use
the ``while read ...`` trick, but for full robustness you have
to know that your filenames are "well behaved" (i.e., they don't
have "weird" characters in them).
I generally prefer the ``find ... -print0 | xargs -0`` idiom
posted elsewhere in this thread, especially if I'm already using
``find``, as all possible weird characters are handled properly.
More information about the Novalug