print command

R

ray

Trying to substitute /bar/ for /foo/ and write the result of the
substitution to a file:
Both of commands are not correct syntactically, missing something or
not possible to print the result from a command ?

perl -pi -e 's/\bbar\b/foo/g' `find . -type f` -print 0| xargs -0
perl -pi -e -print 0| xargs -0 's/\bbar\b/foo/g' `find . -type f`

Please help me.
 
S

Sherm Pendley

Doesn't your 'find' command have an -exec option?

Probably, but that doesn't do the same thing. Using -exec will launch a new
instance of Perl for each file found. That's a *lot* of unnecessary overhead.
Ray's trying to pass a list of all the found files to one instance of Perl.

Something like this:

find . -type f -print0 | xargs -0 perl -pi -e 's/bar/foo/g'

sherm--
 
T

Tad McClellan

ray said:
Both of commands are not correct syntactically,


All of your Perl *is* syntactically correct (though the 2nd
one is semantically incorrect).

missing something or
not possible to print the result from a command ?

perl -pi -e 's/\bbar\b/foo/g' `find . -type f` -print 0| xargs -0


perl -e 's/\bbar\b/foo/g'

compiles just fine (ie. no syntax errors).

perl -pi -e -print 0| xargs -0 's/\bbar\b/foo/g' `find . -type f`


perl -e -print

compiles just fine (ie. no syntax errors).

Negating the return value from print() is likely not what
you were trying for though...

Please help me.


Please ask shell questions in a shell newsgroup.

Pleading is counter-productive, it has an effect opposite of
what you were likely hoping for.

Have you seen the Posting Guidelines that are posted here frequently?
 
U

Uri Guttman

SP> Probably, but that doesn't do the same thing. Using -exec will
SP> launch a new instance of Perl for each file found. That's a *lot*
SP> of unnecessary overhead. Ray's trying to pass a list of all the
SP> found files to one instance of Perl.

SP> Something like this:

SP> find . -type f -print0 | xargs -0 perl -pi -e 's/bar/foo/g'

or you can just run find in backticks and pass that to perl. this
assumes the file count won't blow up the shell which is what xargs will
avoid if you use the right args which aren't set above.

uri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,248
Latest member
MagdalenaB

Latest Threads

Top