[SOLVED] Need a one-liner to change one digit in a variable
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need a one-liner to change one digit in a variable
Good day.
I need advice with assigning a partner hostname to a variable based on the current hostname, using standard tools like awk, sed, cut or tr?
Ie: if the current hostname is LM5SE-J00C01H0, I would like to assign a partner hostname to a new variable, ie: $PARTNER becomes LM5SE-J00C02H0, and visa versa, if $HOSTNAME=LM5SE-J00C02H0, $PARTNER becomes LM5SE-J00C01H0.
I need advice with assigning a partner hostname to a variable based on the current hostname, using standard tools like awk, sed, cut or tr?
Ie: if the current hostname is LM5SE-J00C01H0, I would like to assign a partner hostname to a new variable, ie: $PARTNER becomes LM5SE-J00C02H0, and visa versa, if $HOSTNAME=LM5SE-J00C02H0, $PARTNER becomes LM5SE-J00C01H0.
Thanks in advance,
Bjoern
As mentioned above, what have you tried? Apart from that, are these the only two possible hostnames? If so, you don't need any of the above mentioned tools, just a conditional statement.
If there are more possible hostnames, your question does not provide enough details.
As mentioned above, what have you tried? Apart from that, are these the only two possible hostnames? If so, you don't need any of the above mentioned tools, just a conditional statement.
If there are more possible hostnames, your question does not provide enough details.
Thanks for the replies. I will supply more information:
When I log into any of our systems, I use a virtual IP address to access either of 2 nodes depending which one is the master node at the time. There are times I would like to ssh to the partner node and therefore I have to determine which node I'm on before accessing the partner. However, the partner isn't clearly defined in the /etc/hosts file. Also, the hostnames could be any combination of letters and numbers around the '01' and '02' with the 'H0' on the end the only unchanged pair. For example LM5SE-J00C01H0 and LM5SE-J00C02H0 could be SH2VF-K00C01H0 and SH2VF-K00C02H0 on another system.
I think I did find a solution (seems a weekend R & R helps sorting the brain cells):
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.