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
21353535 10
24535365 6
34213444 9
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
else
echo $sid: Prac1, >> Missing1; #this is my required format
fi;
if cut Prac2 -f1 -d ' ' | grep -v \# | grep "$sid"; then
echo "Found $sid">>error;
else
echo $sid: Prac2, >> Missing2;
fi;
if cut Prac3 -f1 -d ' ' | grep -v \# | grep "$sid"; then
echo "">>error;
else
echo $sid: Prac3, >> Missing3;
fi;
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:
File: Missing
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?
|
Recent comments
6 hours 35 min ago
16 hours 3 min ago
16 hours 53 min ago
20 hours 26 min ago
1 day 50 min ago
1 day 1 hour ago
1 day 3 hours ago
1 day 13 hours ago
1 day 18 hours ago
1 day 19 hours ago