PryGuy
August 25th, 2009, 10:02 AM
Good day, everyone!
The question is: I have a variable, it's an IP address. Say it's '192.168.0.1'. I want to cut characters counting backwards from the end of the string up to the '.' char. Is it possible to do it in pure bash?
I can't just cut a fixed number of characters, 'cause the length of the IP address can be different, eg. '192.168.0.1' and '10.215.215.10'.
Thank you in advance!
UPDATE! I have found the answer!!!
echo "192.168.0.1" | cut -d "." -f 1-3
The question is: I have a variable, it's an IP address. Say it's '192.168.0.1'. I want to cut characters counting backwards from the end of the string up to the '.' char. Is it possible to do it in pure bash?
I can't just cut a fixed number of characters, 'cause the length of the IP address can be different, eg. '192.168.0.1' and '10.215.215.10'.
Thank you in advance!
UPDATE! I have found the answer!!!
echo "192.168.0.1" | cut -d "." -f 1-3