Last active
December 17, 2015 05:49
-
-
Save letsgetrandy/5560480 to your computer and use it in GitHub Desktop.
A handy way to search HTML files for any instances of a particular CSS class name.
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
#!/bin/bash | |
# | |
# Searches all HTML files and matches those where a | |
# particular CSS class name is used | |
if command -v ag >/dev/null 2>&1 | |
then | |
# use silver-searcher if available | |
ag -G "\\.html$" "class=\"[^\"]*\\b$1\\b[^\"]*\"" | |
elif command -v ack >/dev/null 2>&1 | |
then | |
# else, use ack if available | |
ack --html "class=\"[^\"]*\\b$1\\b[^\"]*\"" | |
else | |
# otherwise, just use grep | |
find . -name "*.html" | xargs grep --color=auto -nioP "class=\"[^\"]*\\b$1\\b[^\"]*\"" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use it from the bash command line to recursively search the current directory for
html
files in which the specified class name is found within aclass="..."
attribute.cssgrep some-class-name