I have a txt file that looks like this called locations.txt:
location-1a
location-2c
location-3d
location-4
location-5a
...
I wish to iterate over the locations.txt file within my for loop, each location should be used for 5 nodes, then the next location should be used. so for example, I want the following commands to run,
server create --location location-1a node-1
server create --location location-1a node-2
server create --location location-1a node-3
server create --location location-1a node-4
server create --location location-1a node-5
server create --location location-2c node-6
.....
So far, I only have the following script called script.sh with takes an argument from the cli. I can't change the location like I want to.
mapfile -t locationArr < ~/Documents/files/locations.txt
serverCounter=1
locationCounter=1
counter=1
counter=1
for (( i = 1; i <= $1; i++ ))
do
 server create --location $locationArr[$locationCounter] node-$i
 counter=$((counter+1))
 if [ $counter == 5 ]
 then
  counter=1
  locationCounter=$((locationCounter+1))
done
I want something like
if counter == 5:
 counter=0
 nextline 
So for example if I run script.sh 11, I want the following result,
server create --location location-1a node-1
server create --location location-1a node-2
server create --location location-1a node-3
server create --location location-1a node-4
server create --location location-1a node-5
server create --location location-2c node-6
server create --location location-2c node-7
server create --location location-2c node-8
server create --location location-2c node-9
server create --location location-2c node-10
server create --location location-3d node-11
How do I iterate over the location.txt file within my for loop? Should I convert the text file into some sort of list variable?
 
     
     
    