Clever File-Renaming
Have you ever had to rename files based on a regular expression? In a Unix shell smart combinations of mv with sed can help, but they can also be helpful in shooting yourself in the foot.
The small rename utility from Perlmonks is a blessing, in that it will use Perl regular expressions to do the hard work. The program contains its own help file (perldoc rename) and is easy to use.
I had a whole set of files with a dash as the second character and I wanted that removed:
rename –e 's/^(.)–(.*)$/$1$2/' *
rename applies the Perl script in –e to all files in the directory, and opton –n shows what would be done before it is too late.
Cool.
Post a Comment