Yet more shell scripting
I have been visiting this forum for a couple of weeks now, originally searching for shell scripting advice. Some threads here have been absolutely invaluable.
I have finally got stuck in my Assignment for uni though, I am trying to write a script to calculate missed pracs for students.
I have three files containing prac marks over a semester, they look a little like:
#Prac Marks for class 1
#fomat is SID MARK
I need to compile a file of missed pracs, where no mark is recorded in any particular prac.
what I have so far is:
cut Students -f1 -d: | grep -v \# > Missing-temp; #extract SID from the first column of my Students file.
while read sid extra; do #read SID using extra to catch any extra stuff not needed
if cut Prac1 -f1 -d ' ' | grep -v \# | grep "$sid"; then #cut field 1 out of Prac1, this is the SID field, remove any lines starting with # using grep then find whether the relevant SID is in the Prac file.
echo "Found $sid" >>error; #just for debugging purposes
echo $sid: Prac1, >> Missing1; #this is my required format
if cut Prac2 -f1 -d ' ' | grep -v \# | grep "$sid"; then
echo "Found $sid">>error;
echo $sid: Prac2, >> Missing2;
if cut Prac3 -f1 -d ' ' | grep -v \# | grep "$sid"; then
echo $sid: Prac3, >> Missing3;
done < Missing-temp; #pipe Missing-temp into read, end loop
join -a 1 -a 2 Missing1 Missing2 | join -a 1 -a 2 - Missing3 >> Missing4; #join files together, using -a to ignore any missing bits
sed 's/,$//' <Missing4 | sort -g >Missing; # removes trailing commas and sorts numerically.
rm -f Missing1 Missing2 Missing3 Missing4 Missing-temp; #get rid of temp files
The script works fine on my test data but when I submit it, I get the following error:
Expected: 312349311: Prac1, Prac2
Got: 312349311: Prac1
I have tested for this kind of output in my test files and it works fine. Does anyone have any suggestions as to why the script is not working?