Compare commits

..

2 Commits

Author SHA1 Message Date
a9e4013969 Use awk match instead of grep loop 2024-12-06 01:09:33 +08:00
02da3cf54d Rename to make more sense 2024-12-05 23:31:27 +08:00

View File

@ -1,25 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
INPUT_RULES=$(cat input-rules)
{ {
while read -r LINE while read -r LINE
do do
GREP_EXPR=$( printf "%s" "$LINE" | tr ',' '|' ) GREP_EXPR=$( printf "%s" "$LINE" | tr ',' '|' )
PASS_RULES=0 BEEG_AWK_EXPR=$(
# Loop through rules and find a breaking rule printf "%s" "$INPUT_RULES" |
while read -r RULE grep -E "($GREP_EXPR)\\|($GREP_EXPR)" |
do sed -E 's/(.*)\|(.*)/\1,.*\2/; s&^&/&; s&$&/&' |
GREPC=$( printf "%s" "$LINE" | grep -c "$RULE" ) paste -s -d '@' |
if [[ $GREPC -ne 1 ]] sed 's/@/ \&\& /g'
then )
#printf "%s rule violated for %s \n" "$RULE" "$LINE" AWK_MATCH=$( printf "%s" "$LINE" | awk "$BEEG_AWK_EXPR" | wc -c )
PASS_RULES=1
break
fi
# Filter rules that only has included pages
done <<< "$( < input-rules grep -E "($GREP_EXPR)\\|($GREP_EXPR)" | sed 's/|/,.*/')"
# Don't process for valid lines # Don't process for valid lines
[[ $PASS_RULES -eq 0 ]] && continue if [[ $AWK_MATCH -gt 0 ]] ; then continue; fi
printf "%s\n" "$LINE" printf "%s\n" "$LINE"
done < input-updates done < input-updates