tso tso - 8 months ago 42
Bash Question

Translate numbers (IP address) inside a variable (bash)

My problem is that I'm having an IP address like

This IP address is inside a variable

Now I want to translate the
inside that IP address with a "*".
The "33" can change, so that this number has to be automatically put somewhere in a variable or so.....
I have no clue how to do that. Thanks for any advice :)


In your very specific case you could use:

$ ip=""
$ printf "%s\n" "${ip/33/*}"

And to replace (remove) everything after the last period:

$ ip=""
$ printf "%s\n" "${ip%.*}.*"

The later is POSIX compatible while the first is available in bash (among other shells)