From 294df8690cd9bf7ef4560d76e9fffb6578814c4a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 6 Dec 2016 09:55:17 +0100 Subject: [PATCH] Do only one grep on each of the lists and count the number of non-empty lines in the result. Improves speed by factor of 2x --- pihole | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pihole b/pihole index e1210dc8..a59bbc3c 100755 --- a/pihole +++ b/pihole @@ -67,14 +67,20 @@ setupLCDFunction() { exit 0 } +scanList(){ + grep -E "(^|\s)${domain}($|\s)" "$1" +} + queryFunc() { domain="${2}" lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt) for list in ${lists[@]}; do - count=$(grep -c -E "(^|\s)${domain}($|\s)" $list) + result=$(scanList $list) + # Remove empty lines before couting number of results + count=$(sed '/^\s*$/d' <<< "$result" | wc -l) echo "::: ${list} (${count} results)" if [[ ${count} > 0 ]]; then - grep -E "(^|\s)${domain}($|\s)" ${list} + echo $result fi echo "" done