Created
December 29, 2024 20:52
-
-
Save caracolmzd/ac1875c55c64c0f7e97f47dde95e60e5 to your computer and use it in GitHub Desktop.
Count occurences of CSS class names
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
| # this script counts the occurrences of different class names in input lines | |
| # where classes are specified using the HTML class attribute. | |
| # It then prints the top 10 most frequently occurring class names and their counts. | |
| BEGIN { | |
| FS=" class=" | |
| } | |
| { | |
| for(i=2; i<=NF; i++) { | |
| classes=$i | |
| gsub(/"/,"",classes) | |
| gsub("/>","",classes) #" fix code highlighting | |
| classcounts[classes]++ | |
| } | |
| } | |
| END { | |
| n=asorti(classcounts,sortedcounts) | |
| for(i=n; i>=n-10; i--) { | |
| print sortedcounts[i], classcounts[sortedcounts[i]] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment