Skip to content

Instantly share code, notes, and snippets.

@caracolmzd
Created December 29, 2024 20:52
Show Gist options
  • Select an option

  • Save caracolmzd/ac1875c55c64c0f7e97f47dde95e60e5 to your computer and use it in GitHub Desktop.

Select an option

Save caracolmzd/ac1875c55c64c0f7e97f47dde95e60e5 to your computer and use it in GitHub Desktop.
Count occurences of CSS class names
# 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