Try something like below
#!/bin/bash
while read -r line; do
[[ $line =~ 'client '([^:]+) ]] && iptables -I INPUT -s "${BASH_REMATCH[1]}" -j DROP
done < error.log
This will match everything between "client "
and a colon as the ip (see @John1024
's comment about doing it this way then just matching to colon), using BASH_REMATCH
)
BASH_REMATCH
An array variable whose members are assigned by the =~ binary
operator to the [[ conditional command. The element with index
0 is the portion of the string matching the entire regular
expression. The element with index n is the portion of the
string matching the nth parenthesized subexpression. This vari‐
able is read-only.