Bash script to break apart a Mastery Manager Export
# This code is only for use under adult supervision. Proceed at your own risk.
#!/bin/bashORIGIFS=$IFS# set $IFS to end-of-lineIFS=`echo -en “\n\b”`if ( !$1 )thenecho ‘usage: batch.command Name_Of_MM_Export_To_Process’;break;fifor l in $(cat $1 )doif `echo ${l} | grep ”Student” 1>/dev/null 2>&1`#this line is the header, start a new output filethenfile=$(($file+1))echo $l > $file.txtecho -n ‘.’else# this line is not a header, write it to the current fileecho $l >> $file.txtfidone; # end the loop# return the original IFSIFS=$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
No Comments »
RSS feed for comments on this post. TrackBack URL