Linux Bash - Swap a digit for another in a command
Linux Bash - Swap a digit for another in a command
Hi, here’s a revised version of your request. Let me know if you need further adjustments.
The goal is to update the IP address in the configuration file based on certain network mask conditions. You’re currently extracting the last octet and planning to append a new digit from the range. Consider using a loop or conditional logic to iterate through the range and modify the IP accordingly. Make sure to test each step to avoid errors. Let me know if you’d like help structuring the script further!
Its a bit tricky with different subnet ranges, so i dont know how much you want to get into that but here is a start: a=(${ip//./ }) will give to an array with all the numbers between the dots you can access each number with ${a[0]} ${a[1]} etc. Then you can do what you want to do with the range. If I take my interpretation of your question it would be: a=(${ip//./ }) range="$(($lastoct + $norpi))" newRange=$(($range+${a[3]})) echo "${a[0]}.${a[1]}.${a[2]}.$newRange" EDIT corrected wrong bracket type
This approach would convert the IP address into a numerical format, enabling you to create an array from it.
I made a mistake with the symbols instead of using parentheses. Trying alternatives like a=(${ip//./}) didn’t help, and other characters besides spaces or slashes didn’t work either. I’m not sure why this happens—it’s something I’ve always done without thinking about questioning it.