[Novalug] Fwd: perl help | filename spaces

Ken Kauffman 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. :)

Thanks again.

Ken


On Wed, Mar 17, 2010 at 21:10, Peter Larsen <plarsen at famlarsen.homelinux.com
> wrote:

>  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...
URL: http://calypso.tux.org/pipermail/novalug/attachments/20100317/cf9c0cc6/attachment.html 


More information about the Novalug mailing list