Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: One-line shell script for find and replace

by blazar (Canon)
on Oct 05, 2005 at 08:14 UTC ( [id://497520]=note: print w/replies, xml ) Need Help??


in reply to Re: One-line shell script for find and replace
in thread One-line shell script for find and replace

But this will call perl over and over again which may not be desirable. Of course it may be the best way (up to doing it entirely in perl) to do it, if the files are too many. Update: thanks to EvanCarroll for pointing out my error.

Incidentally I was a big user of xargs myself, until someone pointed out to me the -exec parameter, although I find its syntax to be somewhat awkward -- but I can live with that.

Replies are listed 'Best First'.
Re^3: One-line shell script for find and replace
by EvanCarroll (Chaplain) on Oct 05, 2005 at 08:37 UTC
    This simply isn't true. Read the docs.
    find ./ | xargs perl -e'print "\n@ARGV"'
    Should output one line with all of the arguements sent to perl.

    Alternativly, just for the sake of putting this out there, this can be done without xargs
    find ./ -exec perl -e'print "\n@ARGV" {} \;
    But this would execute numerous copies of perl.

    But, fear not! for find has an altnative syntax!
    find ./ -exec perl -e'print "\n@ARGV"' {} +
    Which is also probably the best way to acomplish this task.


    Evan Carroll
    www.EvanCarroll.com
      This simply isn't true. Read the docs.
      find ./ | xargs perl -e'print "\n@ARGV"'
      Should output one line with all of the arguements sent to perl.
      You're perfectly right. I knew but just forgot it. Indeed this is the reason why at some time I got used to do stuff like
      find . -type f | while read f; do stuff with $f; done
      whenever I suspected that the argument list may have been too long. (Now I generally stick with -exec.)
      Alternativly, just for the sake of putting this out there, this can be done without xargs
      find ./ -exec perl -e'print "\n@ARGV" {} \;
      But this would execute numerous copies of perl.
      Indeed. It was me to point this out in the first place, as you can see in the post you're replying to.
      But fear not for find hsa an altnative syntax!
      find ./ -exec perl -e'print "\n@ARGV"' {} +
      Which is also probably the best way to acomplish this task.
      Interesting. This I authentically didn't know. Of course it's all out there in the manpages, I guess. But generally you learn "this kinda things" as people tell you about them...

        Of course it's all out there in the manpages, I guess.
        Well, it's in the recent man pages. ;-) Notice that James Youngman only added -exec {}+ support to GNU findutils on 15 January 2005. Not sure how commonly this handy (and more secure than xargs) find option is implemented on other Unices.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://497520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-23 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found