Use awk match instead of grep loop
This commit is contained in:
@ -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 ',' '|' )
|
||||||
MATCH_COUNT=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 )
|
||||||
MATCH_COUNT=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
|
||||||
[[ $MATCH_COUNT -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
|
||||||
|
Reference in New Issue
Block a user