<?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 help please in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369304#M61176</link>
    <description>Why not just always sed over it?&lt;BR /&gt;&lt;BR /&gt;sed -i "s/TIMEZONE=\".*\"/TIMEZONE="Asia/Tashkent/" /etc/sysconfig/clock&lt;BR /&gt;&lt;BR /&gt;Since you always want it to be the same way and not dependent on what the previous value was this would be a simpler solution.&lt;BR /&gt;This ofcourse sets the prerequisite that the variable string itself actually exists thou. Which it should.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson</description>
    <pubDate>Tue, 03 Mar 2009 08:04:47 GMT</pubDate>
    <dc:creator>Fredrik.eriksson</dc:creator>
    <dc:date>2009-03-03T08:04:47Z</dc:date>
    <item>
      <title>sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369298#M61170</link>
      <description>this  attached script has to do two task&lt;BR /&gt;1, if there is no ip address of ntp server, then provide it in the /etc/ntp.conf&lt;BR /&gt;&lt;BR /&gt;2, if /etc/ntp.conf contains the wrong IP address of NTP server, then fix it.&lt;BR /&gt;&lt;BR /&gt;Problem:&lt;BR /&gt;following doesnt work&lt;BR /&gt;&lt;BR /&gt;cat /etc/ntp.conf.org | sed 's/$CHECK_SERVER/$STRING/' &amp;gt; /etc/ntp.conf&lt;BR /&gt;&lt;BR /&gt;i.e sed doesnt substitute the value of a variable $CHECK_SERVER with the value of another variable "$STRING"&lt;BR /&gt;&lt;BR /&gt;please help</description>
      <pubDate>Mon, 02 Mar 2009 08:06:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369298#M61170</guid>
      <dc:creator>Maaz</dc:creator>
      <dc:date>2009-03-02T08:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369299#M61171</link>
      <description>One recommendation is to do a&lt;BR /&gt;echo "$CHECK_SERVER -&amp;gt; $STRING"&lt;BR /&gt;and see what the result give you.&lt;BR /&gt;&lt;BR /&gt;I believe this is because in your CHECK_SERVER string you've done an thought error.&lt;BR /&gt;&lt;BR /&gt;CHECK_SERVER=$(grep ^server /etc/ntp.conf | grep -v '127.127.1.0'  | cut -f2 -d" ")&lt;BR /&gt;The cut will give you the result "192.168.0.1" instead of "server 192.168.0.1" which is what you really wanted.&lt;BR /&gt;&lt;BR /&gt;Use the echo method above to verify this, but I think this is the reason.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson</description>
      <pubDate>Mon, 02 Mar 2009 08:29:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369299#M61171</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2009-03-02T08:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369300#M61172</link>
      <description>Hi Thanks Fredrik Eriksson for help/reply&lt;BR /&gt;and thanks for the suggestion&lt;BR /&gt;&lt;BR /&gt;I did a test &lt;BR /&gt;&lt;BR /&gt;# cat file &lt;BR /&gt;this is maaz&lt;BR /&gt;# cp file file.old&lt;BR /&gt;&lt;BR /&gt;# echo $STRING1&lt;BR /&gt;this is maaz&lt;BR /&gt;&lt;BR /&gt;# echo $STRING2&lt;BR /&gt;this is NOT maaz&lt;BR /&gt;&lt;BR /&gt;# cat file.old | sed 's/$STRING1/$STRING2/' &amp;gt; file&lt;BR /&gt;&lt;BR /&gt;# cat file&lt;BR /&gt;this is maaz&lt;BR /&gt;&lt;BR /&gt;i.e no change in the 'file'&lt;BR /&gt;&lt;BR /&gt;please help me in substituting the values of variables via 'sed'</description>
      <pubDate>Mon, 02 Mar 2009 10:11:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369300#M61172</guid>
      <dc:creator>Maaz</dc:creator>
      <dc:date>2009-03-02T10:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369301#M61173</link>
      <description>Use double quote in your sed command:&lt;BR /&gt;&lt;BR /&gt;sed "s/$STRING1/$STRING2/"&lt;BR /&gt;&lt;BR /&gt;Single quotes won't expand the variables.</description>
      <pubDate>Mon, 02 Mar 2009 11:24:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369301#M61173</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2009-03-02T11:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369302#M61174</link>
      <description>Not entirely sure why this wouldn't work. &lt;BR /&gt;It should have if string1="this is maaz" and the file contains "this is maaz".&lt;BR /&gt;&lt;BR /&gt;Something you should know thou is that sed regexps are case sensitive, if you add a "i" at the end (ex. s/pattern/replace/i) this will change the sed regexp to match case insensitive ("A" and "a" will be matched as the same character).&lt;BR /&gt;&lt;BR /&gt;I would try to do this manually first as an experiment.&lt;BR /&gt;# sed -e "s/192.168.0.2/192.168.0.1/" /etc/ntp.conf&lt;BR /&gt;This won't change the file just the output given to you in your shell.&lt;BR /&gt;&lt;BR /&gt;If this works I would try adding one of the variables.&lt;BR /&gt;# sed -e "s/$CHECK_SERVER/192.168.0.1/" /etc/ntp.conf&lt;BR /&gt;&lt;BR /&gt;And so on untill you find the reason why it wasn't changed.&lt;BR /&gt;&lt;BR /&gt;Also I would recommend using only sed to change the file.&lt;BR /&gt;# cp /etc/ntp.conf /etc/ntp.conf.org&lt;BR /&gt;# sed -i "s/$CHECK_SERVER/$STRING/" /etc/ntp.conf&lt;BR /&gt;&lt;BR /&gt;-i tells sed to change the file with the search-replace-expression :)&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson</description>
      <pubDate>Mon, 02 Mar 2009 11:28:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369302#M61174</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2009-03-02T11:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369303#M61175</link>
      <description>thanks Ivan Ferreira, yes double quotes works ;)&lt;BR /&gt;and thanks Dear Fredrik.eriksson for your continuous support and suggestions and excellent tips&lt;BR /&gt;&lt;BR /&gt;another relevant  question&lt;BR /&gt;the following code has to do two task&lt;BR /&gt;1, if there is no TIMEZONE set, then set it in /etc/sysconfig/clock&lt;BR /&gt;2, if there is wrong TIMEZONE in /etc/sysconfig/clock, then fix it&lt;BR /&gt;&lt;BR /&gt;ok, now&lt;BR /&gt;the proper value of timezone in /etc/sysconfig/clock should be &lt;BR /&gt;TIMEZONE="Asia/Tashkent" &lt;BR /&gt;&lt;BR /&gt;right now the value of timezone(wrong) in /etc/sysconfig/clock is&lt;BR /&gt;TIMEZONE="aa/tshknt" &lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;CLOCK=/etc/sysconfig/clock&lt;BR /&gt;TIMEZONE_STRING='TIMEZONE="Asia/Tashkent"'&lt;BR /&gt;CHECK_TIMEZONE=$(grep ^TIMEZONE $CLOCK)&lt;BR /&gt;&lt;BR /&gt;   if [ -z "$CHECK_TIMEZONE" ]; then echo "$TIMEZONE_STRING" &amp;gt;&amp;gt; $CLOCK&lt;BR /&gt;      else cp "$CLOCK" /tmp/clock&lt;BR /&gt;         cat /tmp/clock | sed "s/$CHECK_TIMEZONE/$TIMEZONE_STRING/" &amp;gt; $CLOCK&lt;BR /&gt;   fi&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;upon execution of the above code, I got the following error&lt;BR /&gt;&lt;BR /&gt;sed: -e expression #1, char 36: unknown option to `s'</description>
      <pubDate>Tue, 03 Mar 2009 07:18:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369303#M61175</guid>
      <dc:creator>Maaz</dc:creator>
      <dc:date>2009-03-03T07:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369304#M61176</link>
      <description>Why not just always sed over it?&lt;BR /&gt;&lt;BR /&gt;sed -i "s/TIMEZONE=\".*\"/TIMEZONE="Asia/Tashkent/" /etc/sysconfig/clock&lt;BR /&gt;&lt;BR /&gt;Since you always want it to be the same way and not dependent on what the previous value was this would be a simpler solution.&lt;BR /&gt;This ofcourse sets the prerequisite that the variable string itself actually exists thou. Which it should.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson</description>
      <pubDate>Tue, 03 Mar 2009 08:04:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369304#M61176</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2009-03-03T08:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369305#M61177</link>
      <description>sry, I missed a vital part.&lt;BR /&gt;&lt;BR /&gt;sed -i "s/TIMEZONE=\".*\"/TIMEZONE="Asia\/Tashkent/" /etc/sysconfig/clock</description>
      <pubDate>Tue, 03 Mar 2009 08:05:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369305#M61177</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2009-03-03T08:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369306#M61178</link>
      <description>once again thanks Dear Fredrik.eriksson ;)&lt;BR /&gt;&lt;BR /&gt;&amp;gt;sry, I missed a vital part.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;sed -i "s/TIMEZONE=\".*\"/TIMEZONE="Asia\/Tashkent/" /etc/sysconfig/clock&lt;BR /&gt;&lt;BR /&gt;Dear when I copy and paste the above "sed" on terminal, it didnt execute&lt;BR /&gt;# sed -i "s/TIMEZONE=\".*\"/TIMEZONE="Asia\/Tashkent/" /etc/sysconfig/clock&lt;BR /&gt;&amp;gt;&lt;BR /&gt;(here I type ctrl+c, to get the prompt back)&lt;BR /&gt;&lt;BR /&gt;but following works&lt;BR /&gt;# sed -i 's/TIMEZONE=\".*\"/TIMEZONE="Asia\/Tashkent/' /etc/sysconfig/clock&lt;BR /&gt;&lt;BR /&gt;i.e i used ' instead of "&lt;BR /&gt;&lt;BR /&gt;thanks for your kind support,</description>
      <pubDate>Tue, 03 Mar 2009 09:08:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369306#M61178</guid>
      <dc:creator>Maaz</dc:creator>
      <dc:date>2009-03-03T09:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369307#M61179</link>
      <description>It's another typo.&lt;BR /&gt;&lt;BR /&gt;sed -i "s/TIMEZONE=\".*\"/TIMEZONE=\"Asia\/Tashkent\"/" /etc/sysconfig/clock&lt;BR /&gt;&lt;BR /&gt;You need to escape qoutes that is inside of the search-replace expression.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson</description>
      <pubDate>Tue, 03 Mar 2009 09:29:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369307#M61179</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2009-03-03T09:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: sed help please</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369308#M61180</link>
      <description>Hi thanks  Fredrik.eriksson  &lt;BR /&gt;&lt;BR /&gt;in my previous post, I wrote&lt;BR /&gt;&amp;gt;but following works&lt;BR /&gt;# sed -i 's/TIMEZONE=\".*\"/TIMEZONE="Asia\/Tashkent/' /etc/sysconfig/clock&lt;BR /&gt;&lt;BR /&gt;I didnt notice then, the above sed command doesnt close the quotes in /etc/sysconfig/clock&lt;BR /&gt;&lt;BR /&gt;after running the above sed&lt;BR /&gt;grep ^TIMEZONE /etc/sysconfig/clock&lt;BR /&gt;TIMEZONE="Asia/Tashkent&lt;BR /&gt;&lt;BR /&gt;you can see that closing quotes are missing&lt;BR /&gt;but following definitely works ;)&lt;BR /&gt;sed -i "s/TIMEZONE=\".*\"/TIMEZONE=\"Asia\/Tashkent\"/" /etc/sysconfig/clock&lt;BR /&gt;&lt;BR /&gt;Thanks :)</description>
      <pubDate>Tue, 03 Mar 2009 10:23:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help-please/m-p/4369308#M61180</guid>
      <dc:creator>Maaz</dc:creator>
      <dc:date>2009-03-03T10:23:00Z</dc:date>
    </item>
  </channel>
</rss>

