I have a file called ips.txt
and it has values like below:
cat ips.txt
abc.com. 10.120.20.4 10.120.20.5 ... # there can be many ips separated by a space
xyz.com. 10.120.20.6
I want to read this file line by line with a loop and do some other works.
And als I need to remove that .
as well at the end of each domain name abc.com.
and assign each ip to a variable (if it can be stored to an array, it is great)
So here's what I tried:
input="ips.txt"
while IFS= read -r line
do
echo "$line"
domain="" # need to assign abc.com
ip_one= "" # need to assign the first ip occurence
ip_two= "" # need to assign the second ip occurence
...
ip_n= "" # need to assign the nth ip occurence
# some other commands I need to execute with domain name and all the ips collected
done < "$input"
how can I assign the ip
values to different variables? and use them? It is better if I can Store the IP's in a array like data type so it is more easier as I don't know how many IP's are there for some line in the ips.txt
file.
Can someone help me do this?