Last active
December 7, 2017 23:31
-
-
Save RupGautam/9b3d6c514fbdab9a51bc72ee48910276 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __ScriptVersion="1.0" | |
| #----------------------------------------------------------------------- | |
| # Q5. usage function | |
| #----------------------------------------------------------------------- | |
| CMD_LINE_USAGE="Usage: $0 [-h] [-f file] [-r report]" | |
| function usage () | |
| { | |
| echo $CMD_LINE_USAGE 1>&2; | |
| echo "-h Display this message" | |
| echo "-v version Display script version" | |
| echo "-f file, specific input file " | |
| echo "-r generate a report" | |
| } # ---------- end of function usage ---------- | |
| #----------------------------------------------------------------------- | |
| # Q4. Wrong usage case funtion | |
| #----------------------------------------------------------------------- | |
| function wrong_use() { | |
| echo "Try $0 -h for more information." | |
| } | |
| # ---------- end of function wrong_use ---------- | |
| #----------------------------------------------------------------------- | |
| # Q6. get_student_name funtion | |
| #----------------------------------------------------------------------- | |
| function get_student_name() { | |
| #Check if the provided file exist, if it does parse "username" | |
| filename=$1 | |
| if [ -f $filename ] | |
| then | |
| echo "${filename}" | awk -F"." '{print $1}' | awk -F"_" '{print $NF}' | |
| else | |
| #If file not found echo out error | |
| echo "${filename} NOT FOUND" | |
| fi | |
| # cat ${filename} | while read line | |
| # do | |
| # grep "^[^#;]" $line | grep -o ':[0-9].[0-9]*' | sed 's/://g' | awk '{s+=$1} END {print s}' | |
| # done | |
| } | |
| # ---------- end of get_student_name funtion ---------- | |
| #----------------------------------------------------------------------- | |
| # Q.7 parse_assignment_file | |
| #----------------------------------------------------------------------- | |
| function parse_assignment_file() { | |
| filename=$1 | |
| echo "$filename" | |
| filename=$filename | |
| # grep -o ':[0-9].[0-9]*' $filename | sed 's/://g' | |
| grep -o '".*"' $filename | tr -d '"' | |
| } | |
| # ---------- end of parse_assignment_file ---------- | |
| #----------------------------------------------------------------------- | |
| # Q8. calc_num_of_points | |
| #----------------------------------------------------------------------- | |
| function calc_num_of_points() { | |
| filename=$1 | |
| echo "$filename" | |
| filename=$filename | |
| cat ${filename} | while read line | |
| do | |
| grep -o ':[0-9].[0-9]*' $line | sed 's/://g' | awk '{s+=$1} END {print s}' | |
| done | |
| } | |
| #---------- end of print_final_mark ---------- | |
| #----------------------------------------------------------------------- | |
| # Q3. Handle command line arguments | |
| #----------------------------------------------------------------------- | |
| while getopts "hlf:r:t:" opt; | |
| do | |
| case $opt in | |
| h) usage; exit 0 ;; | |
| v) echo "$0 -- Version $__ScriptVersion"; exit 0 ;; | |
| f) get_student_name $OPTARG ;; | |
| r) parse_assignment_file $OPTARG exit 0 ;; | |
| t) calc_num_of_points $OPTARG exit 0 ;; | |
| * ) echo -e "Invalid args $OPTARG\n"; wrong_use; exit 1 ;; | |
| esac | |
| done | |
| # echo ${get_student_name} | |
| echo ${parse_assignment_file} | |
| echo ${calc_num_of_points} | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment