Skip to content

Instantly share code, notes, and snippets.

@orbitz
Last active December 31, 2015 08:19
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 orbitz/2794f837667e1e3bbbb6 to your computer and use it in GitHub Desktop.
Save orbitz/2794f837667e1e3bbbb6 to your computer and use it in GitHub Desktop.
#! /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
@orbitz
Copy link
Author

orbitz commented Dec 14, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment