Skip to content
Advertisement

How to grep two IP addresses and increase the value of the last number?

I’m pretty new to Linux and writing scripts etc. I have this task where I need to find an IP-address from a database and then grep a bunch of files with this IP and the next one to see, if they have any presence there. Currently I have to first write:

JavaScript

and then

JavaScript

And I have to manually change the last digit from the rwhois and from the grep. I got as far as to write a simple function like this

JavaScript

But of course I’d have to somehow increase the value of the latter input by 1. Any good advice? And a small explanation of what you changed is appreciated so I can learn from this. Thanks!

Advertisement

Answer

It’s simple to just increase the last digit with awk:

JavaScript

Note that this will not handle wrapping (when the last digit is 255), but that shouldn’t be a problem if you don’t need to handle broadcast addresses.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement