Use awk match instead of grep loop

This commit is contained in:
2024-12-06 01:09:33 +08:00
parent 02da3cf54d
commit a9e4013969

View File

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