The problem here is, you're reading from the Apache log and writing to it at the same time. Whatever you added to the log also makes it back into the pipeline through the cat
call (no wordplay intended :) ). This creates a nasty positive feedback loop that will keep working until your file system fills up. The answer to this question may be interesting to you about why this happens.
How should you go about it then? A naive solution would be to modify the file in place like so:
for item in ${!values[@]};do
sed -i "..." "$apacheLog" #cat isn't needed here
done
and don't pipe the output anywhere: the script itself will modify the file in situ. Also see terdon's answer for how to make the sed
call only once (without a loop) so as to improve efficiency.
The problem with this approach, however, is that a live Apache server will likely be logging things to the file as you're working on it and weird things can start happening. A better solution would be to look in the Apache documentation for ways to keep sensitive information out of the logs.
Incidentally, what you're doing doesn't even sanitize the logs: it appends the sanitized lines back into the (still tainted) log file.