<?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: Best sed usage in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108364#M91409</link>
    <description>&amp;gt; In my opinion, this isn't harder to read.&lt;BR /&gt;&lt;BR /&gt;Whateveryousay.</description>
    <pubDate>Mon, 12 May 2008 15:41:52 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2008-05-12T15:41:52Z</dc:date>
    <item>
      <title>Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108358#M91403</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I have 3 different parameters to change in a file and want to use sed, what is the best way to change the value of 3 different strings from the same file - then replace the file ie:&lt;BR /&gt;&lt;BR /&gt;FILE=FILE.cfg&lt;BR /&gt;userbase=xyz&lt;BR /&gt;timeout=5&lt;BR /&gt;defaultentry=local&lt;BR /&gt;&lt;BR /&gt;# cat $FILE | sed -e 's/userbase=xyz/userbase=abc/;&lt;BR /&gt; -e s/timeout=5/timeout=60/ -e s/defaultentry=local/defaultentry/' &amp;gt; ${FILE}.tmp&lt;BR /&gt;&lt;BR /&gt;cp ${FILE}.tmp ${FILE}&lt;BR /&gt;&lt;BR /&gt;is this the best way or is there a more logical method?&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;&lt;BR /&gt;Chris&lt;BR /&gt;</description>
      <pubDate>Mon, 12 May 2008 13:43:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108358#M91403</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-12T13:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108359#M91404</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;If you want to do this with 'sed', do:&lt;BR /&gt;&lt;BR /&gt;# sed -e 's/userbase=xyz/userbase=abc/;s/timeout=5/timeout=60/;s/defaultentry=local/defaultentry/' ${FILE} &amp;gt; ${FILE}.tmp&lt;BR /&gt;&lt;BR /&gt;# mv ${FILE}.tmp ${FILE}&lt;BR /&gt;&lt;BR /&gt;Notice that you do NOT need to run a 'cat' process which 'sed' then reads from a pipe.  This is a waste of a process.&lt;BR /&gt;&lt;BR /&gt;Notice too the change I made in the 'sed' syntax.  A semicolon between the substitution commands with one '-e' switch ahead of the arguments.&lt;BR /&gt;&lt;BR /&gt;Of course, Perl can do an inplace update eliminating the 'mv' step :-)&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 12 May 2008 13:52:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108359#M91404</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-05-12T13:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108360#M91405</link>
      <description>&amp;gt; Notice too the change I made in the 'sed'&lt;BR /&gt;&amp;gt; syntax.&lt;BR /&gt;&lt;BR /&gt;Which makes it harder to read, but does it&lt;BR /&gt;have any other (real) benefits?</description>
      <pubDate>Mon, 12 May 2008 14:22:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108360#M91405</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-05-12T14:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108361#M91406</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Steven: &amp;gt; Notice too the change I made in the 'sed' syntax. Which makes it harder to read, but does it have any other (real) benefits?&lt;BR /&gt;&lt;BR /&gt;In my opinion, this isn't harder to read.  To me, is is more consistent with a script and a script's syntax (which the '-e' signifies in the first place).  Moreover, the syntax becomes exactly compatabile to a Perl script:&lt;BR /&gt;&lt;BR /&gt;# perl -pe 's/userbase=xyz/userbase=abc/;s/timeout=5/timeout=60/;s/defaultentry=local/defaultentry/' file&lt;BR /&gt;&lt;BR /&gt;...which then leads to doing Perl in-place updates, thereby saving the 'mv step:&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e 's/userbase=xyz/userbase=abc/;s/timeout=5/timeout=60/;s/defaultentry=local/defaultentry/' file&lt;BR /&gt;&lt;BR /&gt;...which preserves the original file as "file.old" while leaving the updated file as "file".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 12 May 2008 14:32:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108361#M91406</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-05-12T14:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108362#M91407</link>
      <description>here is what I initally wrote:&lt;BR /&gt;&lt;BR /&gt;userbasedn="userbasedn:ou=people,ou=nis,ou=eu,o=unilever,c=gb"&lt;BR /&gt;ldaptimeout="ldaptimeout:5"&lt;BR /&gt;defaultentrylocation="defaultentrylocation:local"&lt;BR /&gt;&lt;BR /&gt;sed -e 's/userbasedn.*$/'${userbasedn}'/' -e 's/.ldaptimeout.*$/'${ldaptimeout}'/' -e 's/^defaultentrylocation.*$/'${defaulte&lt;BR /&gt;ntrylocation}'/' ${LDAPCFG} &amp;gt; ${LDAPCFGBCK}&lt;BR /&gt;&lt;BR /&gt;and this works however your syntax the command waits ie:&lt;BR /&gt;&lt;BR /&gt;sed -e 's/userbasedn.*$/'${userbasedn}'/';'s/.ldaptimeout.*$/'${ldaptimeout}'/';'s/^defaultentrylocation.*$/'${defaultentrylocation}'/' ${LDAPCFG} &amp;gt; ${LDAPCFGBCK}&lt;BR /&gt;&lt;NO prompt=""&gt;&lt;BR /&gt;&lt;BR /&gt;what have i missed?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/NO&gt;</description>
      <pubDate>Mon, 12 May 2008 14:41:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108362#M91407</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-12T14:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108363#M91408</link>
      <description>Hi (again) Chris:&lt;BR /&gt;&lt;BR /&gt;Ah, so you changed the example :-)&lt;BR /&gt;&lt;BR /&gt;OK, if you are going to use interpolated variables, put them in double-quotes so that the shell expands them:&lt;BR /&gt;&lt;BR /&gt;# sed -e "s/userbasedn.*$/"${userbasedn}"/;s/.ldaptimeout.*$/"${ldaptimeout}"/;s/^defaultentrylocation.*$/"${defaultentrylocation}"/" file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Mon, 12 May 2008 15:24:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108363#M91408</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-05-12T15:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108364#M91409</link>
      <description>&amp;gt; In my opinion, this isn't harder to read.&lt;BR /&gt;&lt;BR /&gt;Whateveryousay.</description>
      <pubDate>Mon, 12 May 2008 15:41:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108364#M91409</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-05-12T15:41:52Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108365#M91410</link>
      <description>of course, the original posting:&lt;BR /&gt;&lt;BR /&gt;sed -e 's/userbase=xyz/userbase=abc/; &lt;BR /&gt;-e s/timeout=5/timeout=60/ -e s/defaultentry=local/defaultentry/' &amp;gt; ${FILE}.tmp &lt;BR /&gt;&lt;BR /&gt;doesn't / wont run anyway...it doesn't understand the "-e" inside the quotes...believe the o.p. is confusing this with the "multiple pattern" in grep</description>
      <pubDate>Mon, 12 May 2008 18:59:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108365#M91410</guid>
      <dc:creator>OldSchool</dc:creator>
      <dc:date>2008-05-12T18:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108366#M91411</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; OldSchool: of course, the original posting...doesn't / wont run anyway...it doesn't understand the "-e" inside the quotes...believe the o.p. is confusing this with the "multiple pattern" in grep &lt;BR /&gt;&lt;BR /&gt;True, but this is legal (and looks like a multiple option/multiple pattern 'grep'):&lt;BR /&gt;&lt;BR /&gt;# sed -e 's/userbase=xyz/userbase=abc/' -e 's/timeout=5/timeout=60/' -e 's/defaultentry=local/defaultentry/' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 12 May 2008 23:05:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108366#M91411</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-05-12T23:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108367#M91412</link>
      <description>&amp;gt;is this the best way or is there a more logical method?&lt;BR /&gt;&lt;BR /&gt;Other than JRF's mv and removal of cat, I would go with multiple -e scripts that he had at the end.&lt;BR /&gt;&lt;BR /&gt;I typically wouldn't use the jammed up embedded commands but having a blank after each ";" may make Steven happy.  :-)&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Steven: Which makes it harder to read, but does it have any other (real) benefits?&lt;BR /&gt;&lt;BR /&gt;Well, as OldSchool points out, JRF's works, and the original didn't.  I would typically use multiple -e.  You could put the script in a file (-f script-file) or use:&lt;BR /&gt;sed -e 's/userbase=xyz/userbase=abc/&lt;BR /&gt;s/timeout=5/timeout=60/&lt;BR /&gt;s/defaultentry=local/defaultentry/' ${FILE} &amp;gt; ${FILE}.tmp&lt;BR /&gt;&lt;BR /&gt;A file wouldn't allow Lawrenzo's ${userbasedn} substitution, unless it was a here document.</description>
      <pubDate>Tue, 13 May 2008 00:54:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108367#M91412</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-05-13T00:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Best sed usage</title>
      <link>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108368#M91413</link>
      <description>lots of discussion here and thanks all.&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Tue, 13 May 2008 13:01:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/best-sed-usage/m-p/5108368#M91413</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-13T13:01:56Z</dc:date>
    </item>
  </channel>
</rss>

