[Novalug] Fwd: perl help | filename spaces
kkauffman at headfog.com
Wed Mar 17 21:18:18 EDT 2010
---------- Forwarded message ----------
From: Ken Kauffman <kkauffman at headfog.com>
Date: Wed, Mar 17, 2010 at 21:17
Subject: Re: [Novalug] perl help | filename spaces
To: Peter Larsen <plarsen at famlarsen.homelinux.com>
Thanks Peter. While you were crafting your response, I was Googlin' around
and came up with this...
find . \( -name cache -prune \) -o -name "*.htm*" -print0 | xargs -0 perl
-i.save -pe "s/news.html/news\//g;"
I also forgot I had to exclude any cache directory or file ... and only do
the operation on htm* files. :)
On Wed, Mar 17, 2010 at 21:10, Peter Larsen <plarsen at famlarsen.homelinux.com
> On Wed, 2010-03-17 at 20:53 -0400, Ken Kauffman wrote:
> So I want to run this one liner, but it doesn't handle filename and
> directory spaces. Does someone with more experience in perl/scripting have
> a proposed solution they would be willing to share with me?
> perl -e "s/news.html/news\//g;" -pi.save $(find . -type f)
> You cannot use commandline replacement like that if you have spaces or
> other special characters.
> Instead look at xargs and used with the -0 parameter (zero terminated
> strings). With "find" you'll use the -print0 to use that format.
> So turn your statement around:
> find . -type f -print0 | xargs -0 perl -e "s/news.html/news\//g;" -pi.save
> That should work.
> Best Regards
> Peter Larsen
> Wise words of the day:
> I am NOT a kludge! I am a computer!
> -- tts
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Novalug