I am creating a script to populate an htaccess file with a blacklist. To do this I have used curl to download a blacklist, which I read into an array using a while statement, that way I can disregard lines that don't begin with 'deny'. Now I want to insert the elements from the array into the .htaccess
file.
The array is called DENY_DATA
and contains entries that look like this:
deny from 64.62.252.163
deny from 167.99.255.132
deny from 27.209.94.238
deny from 64.188.8.229
...
I have inserted two lines into the .htaccess
file between which I want the deny statements to go. They look like this:
#~~~~~~~~~ BLACKLIST START ~~~~~~~~~~
#********* BLACKLIST END **********
I have tried the following using awk. However, this results in the tmp file containing only ${DENY_DATA[@]}
as a string.
awk '/^#~~~~~~~~~/ { printf "%s\n", "${DENY_DATA[@]}" }' .htaccess > tmp.file
I have also tried with sed as per Inserting multiline text from file to another file after pattern and Bash script to insert code from one file at a specific location in another file?. With this, I am left with the original htaccess file but no deny statements.
sed -e '/^#~~~~~~~~~/r printf "%s\n" "${DENY_DATA[@]}"' .htaccess > tmp.file
Is there a simple fix, or is there a better way to approach this?