<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: sed/regular expression question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627177#M726258</link>
    <description>The reason is that local also has exactly the same prefix 192.168.1.1 - to make it unique, you can change your sed to:&lt;BR /&gt;&lt;BR /&gt;sed 's/'$curgw' /'$newgw' /etc/hosts &amp;gt; /var/tmp/hosts &lt;BR /&gt;&lt;BR /&gt;(ie. a space after curgw - that way it will not match 192.168.1.105 as well as 192.168.1.1 since there is a requirement for a space character.)&lt;BR /&gt;&lt;BR /&gt;good luck</description>
    <pubDate>Thu, 06 Dec 2001 21:35:27 GMT</pubDate>
    <dc:creator>Kofi ARTHIABAH</dc:creator>
    <dc:date>2001-12-06T21:35:27Z</dc:date>
    <item>
      <title>sed/regular expression question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627176#M726257</link>
      <description>All,&lt;BR /&gt;&lt;BR /&gt;I want to write a script that edits the ip address for my default gateway in my hosts file.  I am using SED, but appear to have run into a bit of a problem--in that I can't determine how to properly quote the variable within the SED script properly.  For Example:&lt;BR /&gt;-----------------------------------------------#HOSTS FILE&lt;BR /&gt;192.168.1.105 local&lt;BR /&gt;192.168.1.1   router&lt;BR /&gt;&lt;BR /&gt;#VARIABLES&lt;BR /&gt;curgw=192.168.1.1&lt;BR /&gt;newgw=206.36.231.129&lt;BR /&gt;&lt;BR /&gt;sed 's/'$curgw'/'$newgw' /etc/hosts &amp;gt; /var/tmp/hosts&lt;BR /&gt;-----------------------------------------------&lt;BR /&gt;&lt;BR /&gt;My sed statement above replaces the current router ip address with the new router ip address, but it also turns my local ip address into "206.36.231.12905".&lt;BR /&gt;&lt;BR /&gt;Would someone be so kind as to point out what I am doing wrong here?&lt;BR /&gt;&lt;BR /&gt;Thank you,&lt;BR /&gt;&lt;BR /&gt;Grant&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Dec 2001 21:26:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627176#M726257</guid>
      <dc:creator>Grant Wenstrand_1</dc:creator>
      <dc:date>2001-12-06T21:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: sed/regular expression question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627177#M726258</link>
      <description>The reason is that local also has exactly the same prefix 192.168.1.1 - to make it unique, you can change your sed to:&lt;BR /&gt;&lt;BR /&gt;sed 's/'$curgw' /'$newgw' /etc/hosts &amp;gt; /var/tmp/hosts &lt;BR /&gt;&lt;BR /&gt;(ie. a space after curgw - that way it will not match 192.168.1.105 as well as 192.168.1.1 since there is a requirement for a space character.)&lt;BR /&gt;&lt;BR /&gt;good luck</description>
      <pubDate>Thu, 06 Dec 2001 21:35:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627177#M726258</guid>
      <dc:creator>Kofi ARTHIABAH</dc:creator>
      <dc:date>2001-12-06T21:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: sed/regular expression question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627178#M726259</link>
      <description>Need a space after '$curgw'&lt;BR /&gt;&lt;BR /&gt;sed 's/'$curgw' /'$newgw' /etc/hosts&amp;gt; /var/tmp/hosts &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Dec 2001 21:36:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627178#M726259</guid>
      <dc:creator>S.K. Chan</dc:creator>
      <dc:date>2001-12-06T21:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: sed/regular expression question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627179#M726260</link>
      <description>try this:&lt;BR /&gt;&lt;BR /&gt;sed 's/'$curgw'\([[:space:]]*\)/'$newgw'\1/' /etc/hosts &amp;gt; yourfile</description>
      <pubDate>Thu, 06 Dec 2001 21:38:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627179#M726260</guid>
      <dc:creator>Curtis Larson_1</dc:creator>
      <dc:date>2001-12-06T21:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: sed/regular expression question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627180#M726261</link>
      <description>sed 's/'${curgw}' /'${newgw} /'&lt;BR /&gt;&lt;BR /&gt;should do the trick for you.&lt;BR /&gt;&lt;BR /&gt;Note the spaces after curgw and newgw.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Thu, 06 Dec 2001 21:40:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627180#M726261</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-12-06T21:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: sed/regular expression question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627181#M726262</link>
      <description>&amp;lt;&lt;SED&gt;&amp;gt;&lt;BR /&gt;&lt;BR /&gt;Change this to&lt;BR /&gt;sed 's/'$curgw$/'$newgw'&lt;BR /&gt;&lt;BR /&gt;(the $ at the end of curgw tells sed to match it exactly!.)&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;raj&lt;/SED&gt;</description>
      <pubDate>Thu, 06 Dec 2001 21:42:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627181#M726262</guid>
      <dc:creator>Roger Baptiste</dc:creator>
      <dc:date>2001-12-06T21:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: sed/regular expression question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627182#M726263</link>
      <description>Thank you all for your input.  Regretablly, I am not yet successful, but I appear to be getting close using the POSIX character class suggestion of Curtis.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Grant&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Dec 2001 23:21:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627182#M726263</guid>
      <dc:creator>Grant Wenstrand_1</dc:creator>
      <dc:date>2001-12-06T23:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: sed/regular expression question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627183#M726264</link>
      <description>The others are correct about the space but a more general solution is to use a word end mark '\&amp;gt;' (i.e. your fields may be separated by tabs).&lt;BR /&gt;You should also be careful about '.'s in regular expresions. I would have used something like:&lt;BR /&gt;&lt;BR /&gt;#VARIABLES&lt;BR /&gt;curgw='192\.168\.1\.1'  # Note ' quotes \ where " sometimes quote newgw=206.36.231.129 &lt;BR /&gt;sed "s/^$curgw\\&amp;gt;/$newgw/" /etc/hosts &amp;gt; /var/tmp/hosts&lt;BR /&gt;&lt;BR /&gt;The ^ forces replace ONLY at beginning of line. Otherwise you might have the same problem as the space solves but at the beginning of the line. Say you are changing 10.1.1.1 to 10.1.2.1. The address 110.1.1.1 would be changed to 110.1.2.1.&lt;BR /&gt;&lt;BR /&gt;These points are probably not interesting here but in a more complex case they may be.&lt;BR /&gt;&lt;BR /&gt;Good Luck,&lt;BR /&gt;Dave L.&lt;BR /&gt;</description>
      <pubDate>Fri, 07 Dec 2001 05:55:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-regular-expression-question/m-p/2627183#M726264</guid>
      <dc:creator>David W Lauderback</dc:creator>
      <dc:date>2001-12-07T05:55:32Z</dc:date>
    </item>
  </channel>
</rss>

