Last active
August 10, 2021 07:14
-
-
Save mingalevme/47fb8dab2f2a2a39a68dfc7957d7bc8b 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
#!/usr/bin/env sh | |
filename="${1:--}" | |
if [ "$filename" = "-" ]; then | |
filename="/dev/stdin" | |
fi | |
grep_options=( -Po ) | |
if [[ "$OSTYPE" == "darwin"* ]]; then | |
grep_options=( -Eo ) | |
fi | |
first_line="" | |
last_line="" | |
count=0 | |
sum=0 | |
while read -r line; do | |
SIZE=$(echo "$line" | grep "${grep_options[@]}" "HTTP\/1.1\" \d+ \d+" | grep "${grep_options[@]}" "\d+$") | |
if [ $? -ne 0 ]; then | |
continue | |
fi | |
if [ -z "$first_line" ] ; then | |
first_line="$line" | |
fi | |
last_line="$line" | |
count=$(( count + 1 )) | |
sum=$(( sum + SIZE )) | |
done < "$filename" | |
printf "First row: %s\n" "$first_line" | |
printf "Last row: %s\n" "$last_line" | |
printf "count=%s\n" "$count" | |
printf "sum=%s\n" "$sum" | |
if [ $count -eq 0 ]; then | |
printf "AVG=0\n" | |
else | |
printf "AVG=%s\n" $(( sum/count )) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment