-
-
Save orbitz/2794f837667e1e3bbbb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
set -e | |
# Clean up useless files | |
for file in *.txt; do | |
[[ -f "$file" ]] || continue | |
if grep "There are no student comments for this assignment" "$file" >/dev/null && | |
grep "There is no student submission text data for this assignment." "$file" >/dev/null; then | |
echo "Deleting $file" | |
rm "$file" | |
continue | |
fi | |
done | |
# Rename _attempts_ | |
for file in *_attempt_*; do | |
[[ -f "$file" ]] || continue | |
newfile=$(echo "$file" | awk '{ split($0, n, "_"); split($0, e, "."); printf "%s.%s", n[2], e[length(e)] }') | |
mv "$file" "$newfile" | |
echo "Renaming $file to $newfile" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Barely tested.
Shows some good bashisms though: for example use *blah instead of $(ls *blah), and always check if the file actually exists in the loop.
Always use -e
The creation of the new filename is pretty ghettotastic though