Moosh - Set Course ID

Based on a list of course ids will set their idnumber field as Faculty$(IDOFPARENTFACULTY)_Campus

#!/bin/bash

while read p;
do
        a=$(echo $p)
        b=$(echo "Faculty")

        #Returns faculty id based on course id of info page
        c=$(su -c "psql -U postgres -d moodle2018-utf8 -t -c \"SELECT MC2.id FROM mdl_course LEFT JOIN mdl_course_categories MC1 ON MC1.id=mdl_course.category LEFT JOIN mdl_course_categories MC2 ON MC2.id=MC1.parent LEFT JOIN mdl_course_categories MC3 ON MC3.id=MC2.parent LEFT JOIN mdl_course_categories MC4 ON MC4.id=MC3.parent WHERE mdl_course.id='$p';\"" postgres)
        #Returns campus name based on course id of info page
        d=$(su -c "psql -U postgres -d moodle2018-utf8 -t -c \"SELECT MC1.name FROM mdl_course LEFT JOIN mdl_course_categories MC1 ON MC1.id=mdl_course.category LEFT JOIN mdl_course_categories MC2 ON MC2.id=MC1.parent LEFT JOIN mdl_course_categories MC3 ON MC3.id=MC2.parent LEFT JOIN mdl_course_categories MC4 ON MC4.id=MC3.parent WHERE mdl_course.id='$p';\"" postgres)

                echo $a,$b,$c,$d >> output.dmp
done<test2
cat output.dmp | sed s/"Dublin Campus"/D/g | sed s/"Cork Campus"/C/g | sed s/"Limerick Campus"/L/g | sed s/"Moscow Campus"/M/g | sed s/"Waterford Campus"/W/g | sed s/"Virtual Campus"/V/g | sed s/"Dublin Tara St"/1/g | sed s/"Sarajevo Campus"/$/g | sed s/" "//g> clean2
cat clean2 | awk -F "," '{ print "update mdl_course set idnumber = '\''" $2 $3 "_" $4 "'\'' where id = '\''" $1 "'\'';"}'