sed + update 4 different IP's in hosts file in one sed command

yael

how to run the follwoing sed command in one command line?

 sed -i s'/12.1.0.11/#12.1.0.11/g' /etc/hosts
 sed -i s'/12.1.0.12/#12.1.0.12/g' /etc/hosts
 sed -i s'/12.1.0.21/#12.1.0.21/g' /etc/hosts
 sed -i s'/12.1.0.22/#12.1.0.22/g' /etc/hosts

my target is to update the target host file VIA ssh

I not want to run the ssh 4 times!

example

 ssh linux1  sed -i    s'/12.1.0.11/#12.1.0.11/g' ................. /etc/hosts 
MelBurslan
ssh remote_host "sed -i -e 's/12.1.0.11/#12.1.0.11/g' -e 's/12.1.0.12/#12.1.0.12/g' -e 's/12.1.0.21/#12.1.0.21/g' -e's/12.1.0.22/#12.1.0.22/g' /etc/hosts"

I'm pretty sure you can wildcard these values but dealing with regex over remote connections is not my idea of fun as it may require a lot of escape characters and gets out of hand quickly

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related