Skip to content

Instantly share code, notes, and snippets.

@chrismacdermaid
Forked from trammell/rename
Created September 8, 2017 15:47
Show Gist options
  • Select an option

  • Save chrismacdermaid/493c539e53d72c825e797b67c7e5e14d to your computer and use it in GitHub Desktop.

Select an option

Save chrismacdermaid/493c539e53d72c825e797b67c7e5e14d to your computer and use it in GitHub Desktop.
Perl rename script
#!/usr/bin/perl
# Usage: rename perlexpr [files]
($regexp = shift @ARGV) || die "Usage: rename perlexpr [filenames]\n";
if (!@ARGV) {
@ARGV = <STDIN>;
chomp(@ARGV);
}
for (@ARGV) {
$old_name = $_;
eval $regexp;
die $@ if $@;
rename($old_name, $_) unless $old_name eq $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment