Skip to content

Instantly share code, notes, and snippets.

@ttsiodras
Last active January 16, 2021 10:22
Show Gist options
  • Save ttsiodras/0dd550d817c59c74c43d63c808a0f3b2 to your computer and use it in GitHub Desktop.
Save ttsiodras/0dd550d817c59c74c43d63c808a0f3b2 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Commenting on https://www.youtube.com/watch?v=Qiu0jlsp3ws
# Much faster than the original, using bash arrays, as Brock wanted to do this initially.
# Also avoids using hardcoded numbers (takes the number of students from the array length)
#
# $ time ./students_brock.sh
#
# real 0m0.170s
# user 0m0.170s
# sys 0m0.032s
#
# $ time ./students_thanassis.sh
#
# real 0m0.026s
# user 0m0.026s
# sys 0m0.000s
class_dates=("Jan. 20" "Jan. 22" "Jan. 25" "Jan. 27" "Jan. 29" "Feb. 1" "Feb. 3" "Feb. 5" "Feb. 8" "Feb. 10" "Feb. 12" "Feb. 15" "Feb. 17" "Feb. 19" "Feb. 22" "Feb. 24" "Feb. 26" "Mar. 1" "Mar. 3" "Mar. 5" "Mar. 8" "Mar. 10" "Mar. 12" "Mar. 15" "Mar. 17" "Mar. 19" "Mar. 22" "Mar. 24" "Mar. 26" "Mar. 29" "Mar. 31" "Apr. 2" "Apr. 5" "Apr. 7" "Apr. 9" "Apr. 12" "Apr. 14" "Apr. 16" "Apr. 19" "Apr. 21" "Apr. 23")
num_of_students=1
num_of_days=0
until (( num_of_days >= ${#class_dates[@]} ))
do
while read -r l; do
if ((num_of_students==1)); then
class_date=${class_dates[$num_of_days]}
if [ -z "$class_date" ]; then
break
fi
echo "--------------------------"
echo "$class_date"
((num_of_days++))
fi
echo "$l"
((num_of_students++))
if ((num_of_students>15)); then
num_of_students=1
fi
done < class-list.txt
done > attendance-days.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment