-
-
Save sixman9/4709513 to your computer and use it in GitHub Desktop.
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 | |
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