Skip to content

Instantly share code, notes, and snippets.

@alghanmi
Created February 9, 2014 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alghanmi/8903193 to your computer and use it in GitHub Desktop.
Save alghanmi/8903193 to your computer and use it in GitHub Desktop.
Rename a set of files in a directory
#!/bin/bash
#
# Batch rename assignment submission files.
# Input format: PA1 Submission_username_attempt_2014-02-06-14-05-19_tp.cpp.zip
# Output format: pa1_username.zip
# Accepted file formats: zip and gz
#
USAGE_MESSAGE="Perform a batch rename or all submission files in a directory.
Usage:
$0 "
FILES="*.gz *.zip"
for i in $FILES
do
new_name=$(echo "$i" | sed 's/\(.*\)\ [S|s]ubmission_\(.*\)_.*_.*_.*\.\(.*\)$/\L\1_\2.\3/')
echo "mv '$i' '$new_name'"
mv "$i" "$new_name"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment