Bash script to break apart a Mastery Manager Export

# This code is only for use under adult supervision. Proceed at your own risk. 🙂
#!/bin/bash
ORIGIFS=$IFS
# set $IFS to end-of-line
IFS=`echo -en “\n\b”`
if ( !$1 )
then
echo ‘usage: batch.command Name_Of_MM_Export_To_Process’;
break;
fi
for l in $(cat $1 )
do
if `echo ${l} | grep  “Student” 1>/dev/null 2>&1`
#this line is the header, start a new output file
then
file=$(($file+1))
echo $l > $file.txt
echo -n ‘.’
else
# this line is not a header, write it to the current file
echo $l >> $file.txt
fi
done;  # end the loop
# return the original IFS
IFS=$ORIGIFS
plue a little one liner to rename the files using line 2, column 2 as the title.
n=0 ; for i in $(ls) ; do mv $i $(cat $i | head -n 2 | tail -n 1 | cut -d, -f2 | tr ‘ ‘ ‘_’ | tr ‘/’ ‘-‘ | tr -d ‘”‘)–$n.txt ; n=$(($n+1)) ; done

Leave a Reply