1

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

2 Answers 2

7

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.

2
  • 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, 2012 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, 2012 at 23:28
0

I needed more trailing slashes evidently... =(

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

1
  • 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, 2012 at 23:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .