#1  
Old 26th April 2007, 07:09
Wraith Wraith is offline
Junior Member
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
Reply With Quote
Sponsored Links
  #2  
Old 27th April 2007, 04:16
ghostdog74 ghostdog74 is offline
Junior Member
 
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you can use awk


Code:
awk -v file="Prac1" ' BEGIN {  # get all sids of Prac1 into array
		while( (getline line < file )>0 ) { 
			if (line ~ /^#/ ) continue #skip comments 
			mprac[line]
		}
      }
      /^#/ {next} #skip comments line in Students file
	{ 		
		if (!( $1 in mprac )) {
			print "Sid: " $1 " not in " FILENAME
		}
	
	}
	
' "Students"
Reply With Quote
  #3  
Old 27th April 2007, 05:18
Wraith Wraith is offline
Junior Member
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the advice. I finally figured out that I needed to sort my Prac files before joining them *doh!*

Oh, well
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting Help... webking Programming/Scripts 3 19th April 2007 19:13
ISPC 2.2.9: Invalid user shell on Ubuntu/Debian martinfst Developers' Forum 4 13th January 2007 15:28
php scripting and shell commands alexnz Programming/Scripts 3 8th August 2006 16:30
Shell nveid General 5 27th March 2006 14:49
Impressive shell scripting namit Programming/Scripts 8 25th March 2006 15:50


All times are GMT +2. The time now is 16:46.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.