Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The latest addition to my renaming-toolbelt has been `perl-rename'. This thing is just wonderful: I can unleash all the power of perl-based regexes to rename things in bulk.

Case in point: I had a directory containing thousands of .jpg images imported from a foreign filesystem, and all of those files had tildes in them, something like:

  $ ls -1
  EL+�CTRICO_0001.jpg
  EL+�CTRICO_0002.jpg
  EL+�CTRICO_0003.jpg
  ...
You get the idea; note those ugly unrepresentable characters over there. On the original filesystem they read as "ELÉCTRICO", but that tilde was saved using who knows what encoding, and I simply wanted to get rid of them and have nice ascii "ELECTRICO_xxxx.jpg" files. After finding out that the strange unrepresentable character was the byte 0xEB (so, in order to form an "É" you needed those two characters together: a literal '+' and 0xEB), I could do the bulk renaming with just:

  $ perl-rename 's/\+\xeb/E/' *.jpg
Felt so good!


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: