Skip to content

Instantly share code, notes, and snippets.

@cirrusUK
Created March 12, 2020 23:29
Show Gist options
  • Save cirrusUK/f04c7ed4721089b916c3431a5d0879e1 to your computer and use it in GitHub Desktop.
Save cirrusUK/f04c7ed4721089b916c3431a5d0879e1 to your computer and use it in GitHub Desktop.
#! /usr/bin/perl
# rename.pl -- rename files by finding a fixed pattern and replace it by other
# Carlos Duarte, 031105
# a clone of the rename(1) utility present in most linux distributions
use strict;
if (@ARGV < 3) {
print "usage: $0 srcpat dstpat files...\n";
exit 1;
}
my $srcpat = shift;
my $dstpat = shift;
for (@ARGV) {
my $old = $_;
s/\Q$srcpat\E/$dstpat/;
my $new = $_;
$old eq $new and next;
print "$old -> $new\n";
rename $old, $new;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment