Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

this one should be simple for anyone who knows the correct way to escape. I'm attempting to batch rename a few hundred files that had \u0026amp; pushed into the file names instead of and or &. I tried using:

rename s/"\\u0026amp;"/"and"/g * but and getting names like Excision \uand Datsik - Calypso.mp3 you can see the \u wasn't escaped properly. What's the way to escape my \??

Thanks

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Not sure why you're using quotes like that. Here's how I use rename:

rename 's/search/replace/' *

And here's it in action:

oli@bert:~/Desktop/rawr$ ls
pie\u333.sh
oli@bert:~/Desktop/rawr$ rename 's/\\u333/PIE/' *
oli@bert:~/Desktop/rawr$ ls
piePIE.sh

Your quotes seem to be throwing it off.

share|improve this answer
    
You're right, it was requiring it to need ANOTHER trailing slash, see above (or below, depending on post angle). Up for noticing it too. –  ehime Apr 16 '12 at 23:20
1  
Backslash is interpreted by the shell within double quotes (not single), so Perl sees s/\u0026amp;/and/g. \u means "uppercase next char", which pointlessly capitalizes 0. So, it's equivalent to s/0026amp;/and/g: only the 0026amp; is replaced and the \u is left behind. Short story is you should always use singlequotes with rename. –  poolie Apr 16 '12 at 23:28
add comment

I needed more trailing slashes evidently... =(

rename s/"\\\u0026amp;"/"and"/g *

share|improve this answer
    
If you're going to double-escape the backslashes, you should really have four: otherwise you're just relying on the shell expanding \u to \u and that won't work in other cases. –  poolie Apr 16 '12 at 23:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.