For example I have IP addresses list
192.168.20.5
192.168.20.12
192.168.20.141
How to remove all symbols after last dot and get this list (below) at the output
192.168.20.
192.168.20.
192.168.20.
I tried this:
LAN=$(nslookup localhost | awk '{print $2}' | head -1)
hosts=$(echo "${LAN::-1}"{1..254} | xargs -n1 -P0 ping -c 1 | grep "bytes from" | awk '{print $4}')
But ::-1
not suitable, because the number of digits may vary