Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: perl code to replace

by hsinclai (Deacon)
on Feb 10, 2011 at 14:02 UTC ( [id://887452]=note: print w/replies, xml ) Need Help??


in reply to perl code to replace

If you happen to be in a bash shell, then you hardly need to invoke Perl, since you have builtins at your disposal..
for N in *.xml; do mv $N ${N/%xml/txt} done
but if you must do that in Perl you can
perl -e 'qx!for N in *.xml\; do mv \$N \${N/%xml/txt}\; done!;'
:)

Note, though, TMTOWTDI: site:perlmonks.org rename files directory


Also this: Re: What one-liners do people actually use? is awesome.

correction: /%xml/ not /xml/ good catch suhailck!

Replies are listed 'Best First'.
Re^2: perl code to replace
by suhailck (Friar) on Feb 10, 2011 at 17:24 UTC
    Your bash script replaces filename like "xml.xml" to "txt.xml". I think you need to change the script as follows inorder to work as expected,

    mv $N ${N/%xml/txt}

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-04-19 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found