I have an associative array that I create from a file for getting failed login attemps per user. The array looks like this:
declare -Ai hash
while read -r -a array; do
[[ "${array[5]} ${array[6]}" == "Failed password" ]] && hash[${array[8]}]+=1
done < $FILEPATH
One of the users that comes up is listed as invalid
and I'd like to change the string to UNKNOWN
. So how do I iterate over the hash and find the string I need and replace its value?
Something like this?
for i in "${!hash[@]}"; do
# (if $i == 'invalid', replace with 'UNKNOWN') ??
done
What would be the syntax for that replace?