0
new=`zcat file.xml.gz | grep :133 | grep 192* | tail -n 1` 
    && gunzip file.xml.gz &&  sed -i 's#$new#<value>
    tcp://192.164.1.5:133</value>#g' file.xml && gzip file.xml

The output of new=<value>tcp://192.164.1.23:133</value>

Here I need to replace the IP 192.164.1.23 with 192.168.1.5

The script will work if I give tcp://192.164.1.23:133 instead of $new. But I want to read it from $new.

Any help......

SANITH
  • 3,147
  • 3
  • 13
  • 15
  • note also that `.` is a meta character and you need to use `\.` to represent it literally.. see https://stackoverflow.com/questions/29613304/is-it-possible-to-escape-regex-metacharacters-reliably-with-sed – Sundeep Nov 15 '17 at 04:39
  • I've checked the link that you posted. But it didn't solve my problem. I need sed to replace the string. Here the script works perfectly if I give the output of $new directly. But I need the sed to read information from the $new variable. – SANITH Nov 15 '17 at 04:56
  • Yes and the duplicate link shows how to use a variable inside a sed statement, thus solving your problem. – Nic3500 Nov 15 '17 at 05:03
  • perhaps separate out the commands? chaining them like this perhaps doesn't allow for value of `new` to be visible for other commands? – Sundeep Nov 15 '17 at 05:04
  • I've echoed the output of $new with "echo $new" and its giving the desired output tcp://192.164.1.23:133 – SANITH Nov 15 '17 at 05:14

0 Answers0