Created
November 25, 2017 14:51
-
-
Save nbyouri/28a312bfddb1732d392312605e21acf3 to your computer and use it in GitHub Desktop.
Awk script to extract file statistic from a har file
This file contains 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
function FileStats(file) { | |
nb_js = 0 | |
nb_img = 0 | |
nb_css = 0 | |
nb_others = 0 # also html/text | |
nb_lines = 0 | |
cmd = sprintf("%s %s", "jq '(.log.entries[]|[ .request.url])|@csv'", file) | |
while (cmd|getline) { | |
if (/\.png|\.jpg|\.gif/) { | |
nb_img++ | |
} else if (/\.css/) { | |
nb_css++ | |
} else if (/\.js/) { | |
nb_js++ | |
} else { | |
nb_others++ | |
} | |
nb_lines++ | |
} | |
printf("img : %.2f%%\n", (nb_img/nb_lines)*100) | |
printf("js : %.2f%%\n", (nb_js/nb_lines)*100) | |
printf("css : %.2f%%\n", (nb_css/nb_lines)*100) | |
printf("others : %.2f%%\n", (nb_others/nb_lines)*100) | |
} | |
BEGIN { | |
if (ARGC < 2 || ARGC > 2) | |
print "Please specify the csv file" | |
else | |
FileStats(ARGV[1]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment