Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Accepted Answer
Hi there,
There are probably multiple ways to do it, but I would personally use a for loop to loop through each of the lines fo the file and then use printf to construct the redirect rule as follows:
#!/bin/bash
if [ "$#" -eq 0 ]; then
echo "Usage: ./rewrite.sh <domain> <file>"
exit
else
DOMAIN=${1}
FILE=${2}
fi
OLDIFS="$IFS"
IFS=$'\n' # bash specific
for line in $(cat ${FILE})
do
old=$(echo $line | awk '{print $1}')
new=$(echo $line | awk '{print $2}')
printf "rewrite ^/%s$ https://${DOMAIN}/%s permanent;\n" "$old" "$new"
done
IFS="$OLDIFS"
Quick rundown:
awk we get the old and the new URLs as we follow the conversion that the first one is the old URL and the second is the new oneprintf to construct the rulesThis will print the results on the screen and you can copy them from there. Or alternatively, when running the script you could send the STDOUT to a file: bash script.sh domain.com file.txt > new_rules.txt.
Hope that this helps! Best, Bobby