Created
December 5, 2016 03:16
-
-
Save tuannvm/863d54c06ea4a92535e96ad51039885d 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
#!/bin/bash | |
root=/root/devops/tasks | |
find $root -type f -name '*README.txt*' > $root/file.txt | |
echo "" > $root/subjects.txt | |
while read line; do | |
sed -n '/\-\-\-/,/\-\-\-/{/\-\-\-/b;/\-\-\-/b;p}' "$line" >> $root/subjects.txt | |
done < $root/file.txt | |
sed -i '/^\s*$/d' $root/subjects.txt | |
awk '!seen[$0]++' $root/subjects.txt > $root/subjects.tmp && mv $root/subjects.tmp $root/subjects.txt | |
sort $root/subjects.txt -o $root/subjects.txt | |
while read subject; do | |
total=0 | |
course="" | |
echo "" > $root/courses.txt | |
while read line; do | |
score=`sed -nr 's|([0-9])/([0-9]+)|\1|p' "$line"` | |
max=`sed -nr 's|.*/([0-9]+)|\1|p' "$line"` | |
different=`expr "$max" - "$score"` | |
tmpSubject=`sed -n '/\-\-\-/,/\-\-\-/{/\-\-\-/b;/\-\-\-/b;p}' "$line"` | |
if ([ "$subject" = "$tmpSubject" ] && [ "$different" != 0 ]); then | |
echo "$line" | sed -r -e 's|/root/devops/tasks/(.*)/README.txt|\1|p' -e '/^\s*$/d' | uniq >> $root/courses.txt | |
total=$(($total + $different)) | |
fi | |
done < $root/file.txt | |
if [ "$total" != 0 ]; then | |
echo "$subject ""("$total")" | |
#echo "$course" | sed -e '/^\s*$/d' -e 's/.*/\-\-&/' | |
sort $root/courses.txt -o $root/courses.txt | |
while read course; do | |
echo "$course" | sed -e '/^\s*$/d' -e 's/.*/\-\-&/' | |
done < $root/courses.txt | |
fi | |
printf "\n" | |
done < $root/subjects.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment