Skip to content

Instantly share code, notes, and snippets.

@gbakernet
Created October 6, 2010 04:00
Show Gist options
  • Save gbakernet/612799 to your computer and use it in GitHub Desktop.
Save gbakernet/612799 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
#Create a list of files with ,0 and ,1 issues.
open(FILES, 'find . -regextype posix-extended -iregex .*,[0-9]+[\.][a-z]+$ |');
@theFiles=<FILES>;
close(FILES);
foreach $file (@theFiles)
{
# Remove end of line
chomp($file);
if ($file =~ /^\.\/([^\/]*)[\/](.*)?$/ ) {
# Groups from regex
$filename = $2;
$catalog = $1;
$catalogfile = "./${catalog}.html";
# Create a search regular expression out of the $filename
$find = $filename;
$find =~ s/[\/]/(\\\/|\\\\)/g;
#($F1, $F2, $Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/
# Create a replacement expression out of $filename
$replace = $filename;
$replace =~ s/[\/]/\//g;
$replace =~ s/,[0-9]+([\.][a-z]+)/$1/g;
$replaceEscaped = quotemeta($replace);
# new file name for renaming
$newfilename = $filename;
$newfilename =~ s/$find/$replace/;
print "\nFound ${filename}, replacing in ${catalogfile}";
# Modify the catalog.html reference to the file
system("perl -pi -e 's/$find/$replaceEscaped/' ${catalogfile}");
# Rename the actual file
system("mv -f ./${catalog}/$filename ./${catalog}/$newfilename");
print "\n-> Replaced with $newfilename";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment