Skip to content

Instantly share code, notes, and snippets.

@sixman9
Forked from Boldewyn/cssgrep.sh
Created February 4, 2013 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixman9/4709513 to your computer and use it in GitHub Desktop.
Save sixman9/4709513 to your computer and use it in GitHub Desktop.
#!/bin/bash
function _usage() {
cat <<USAGE
usage: $(basename $0) PATTERN [FILES]
Print the HTML that matches the CSS selector PATTERN.
USAGE
}
PATTERN=$1
shift
FILES="$@"
if [[ $PATTERN == "-h" || $PATTERN == "--help" ]]; then
_usage
exit
fi
if [[ $# == 0 ]]; then
FILES=.
fi
for file in $(find $FILES -type f -name \*.html -or -name \*.htm)
do
# Ignore errors, write the results to standard output.
CONTENT=$(hxnormalize -l 240 -x "$file" 2>/dev/null | hxselect "$PATTERN")
if [[ $CONTENT != "" ]]; then
echo -e "\e[32m$file: \e[0m$CONTENT"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment