Created
December 7, 2017 20:52
-
-
Save RupGautam/030600b7a1317227d21d278bb82a9234 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() { | |
| #grep -o ':[0-9].[0-9]*' assignment_1_gautam-r.txt | sed 's/://g' | |
| cat ${filename}; | |
| # grep -o ':[0-9].[0-9]*' $filename | sed 's/://g' | |
| # get_student_name "$filename" | |
| exit | |
| } | |
| # filename="bla" | |
| # get_student_name $filename | |
| # filename="ble" | |
| # parse_assignment_file $filename | |
| # ---------- end of parse_assignment_file ---------- | |
| #----------------------------------------------------------------------- | |
| # Q8. calc_num_of_points | |
| #----------------------------------------------------------------------- | |
| function calc_num_of_points() { | |
| echo "calling calc_num_of_points function " | |
| } | |
| #---------- end of print_final_mark ---------- | |
| #----------------------------------------------------------------------- | |
| # Q3. Handle command line arguments | |
| #----------------------------------------------------------------------- | |
| while getopts "hl:f:r" 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 ;; | |
| * ) echo -e "Invalid args $OPTARG\n"; wrong_use; exit 1 ;; | |
| esac | |
| done | |
| echo ${get_student_name} | |
| echo ${parse_assignment_file} | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment