#!/usr/bin/env bash

# Use $1 as an update (e.g., '+ 7') of grades in files specified by
# remaining arguments (in standard format of -grade.txt files).

update=$1
shift

for file in $*; do
  origscore=`sed -n 's+[^0-9]*\([0-9]*\)/.*+\1+p' $file`
  newscore=`expr $origscore $update`
  if [[ $origscore -gt 0 ]]; then
    echo 'y' | subst "+$origscore/+$newscore/+" $file
  fi
done
