Domanda

I am creating a script that I can run and it will simply ask me the common location name...i.e SEC-DF1 and it will fetch the ip of that site from within script. My problem is taking that IP and replacing

right=IP_ADDRESS

with

right=NEW_IP_ADDRESS

I need this so I can call the script as I will be changing the value of right so often for testing.

I have been messing with sed until someone mentioned awk...this stuff has such horrid documentation I keep getting all types errors or weird results on the test file I am messing with.

È stato utile?

Soluzione

Since this is a straight forward substitution, I would just use sed:

sed -e 's/^right=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/right=192.168.1.92/' filename

This will match right= at the beginning of a line followed by an IP address and replace it with the IP of your choosing.

Altri suggerimenti

This command will modify your script:

NEW_IP_ADDRESS=101.102.103.104 sed -i "s/^(right=).*$/\\1$NEW_IP_ADDRESS/" script
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top