<?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: Replace Multiple Strings on 1 file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259031#M888178</link>
    <description>If I understand correctly,U need to replace &lt;BR /&gt;&lt;BR /&gt;sed "s%${oldfile}%${newfile}%g" FILE1 &amp;gt; FILE2&lt;BR /&gt;&lt;BR /&gt;with&lt;BR /&gt;&lt;BR /&gt;sed "s%${oldfile}%${newfile}%g" FILE1 &amp;gt;&amp;gt; FILE2&lt;BR /&gt;&lt;BR /&gt;Regds,&lt;BR /&gt;&lt;BR /&gt;Kaps</description>
    <pubDate>Mon, 26 Apr 2004 07:54:08 GMT</pubDate>
    <dc:creator>KapilRaj</dc:creator>
    <dc:date>2004-04-26T07:54:08Z</dc:date>
    <item>
      <title>Replace Multiple Strings on 1 file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259030#M888177</link>
      <description>All &lt;BR /&gt;&lt;BR /&gt;I am trying to perform the following now I can't use perl I need to replace multiple patterns in a file e.g&lt;BR /&gt;&lt;BR /&gt;for p in 1 2 3 4 &lt;BR /&gt;do&lt;BR /&gt;oldfile=`grep $p /tmp/old`&lt;BR /&gt;newfile=`grep $p /tmp/new`&lt;BR /&gt;&lt;BR /&gt;sed "s%${oldfile}%${newfile}%g" FILE1 &amp;gt; FILE2&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;now I  need the changes for all instances of the for loop to be saved in the 1 file any suggestions ????&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Apr 2004 07:50:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259030#M888177</guid>
      <dc:creator>Stephen Kennedy_2</dc:creator>
      <dc:date>2004-04-26T07:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Multiple Strings on 1 file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259031#M888178</link>
      <description>If I understand correctly,U need to replace &lt;BR /&gt;&lt;BR /&gt;sed "s%${oldfile}%${newfile}%g" FILE1 &amp;gt; FILE2&lt;BR /&gt;&lt;BR /&gt;with&lt;BR /&gt;&lt;BR /&gt;sed "s%${oldfile}%${newfile}%g" FILE1 &amp;gt;&amp;gt; FILE2&lt;BR /&gt;&lt;BR /&gt;Regds,&lt;BR /&gt;&lt;BR /&gt;Kaps</description>
      <pubDate>Mon, 26 Apr 2004 07:54:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259031#M888178</guid>
      <dc:creator>KapilRaj</dc:creator>
      <dc:date>2004-04-26T07:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Multiple Strings on 1 file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259032#M888179</link>
      <description>a double &amp;gt;&amp;gt; just causes the rest of the contents to copied to file2 for each iteration of the for loop I just need the pattern changed....</description>
      <pubDate>Mon, 26 Apr 2004 08:04:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259032#M888179</guid>
      <dc:creator>Stephen Kennedy_2</dc:creator>
      <dc:date>2004-04-26T08:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Multiple Strings on 1 file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259033#M888180</link>
      <description>Can you post what the files "oldfile" and "newfile" look like?&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 26 Apr 2004 08:04:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259033#M888180</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2004-04-26T08:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Multiple Strings on 1 file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259034#M888181</link>
      <description>Example of what I am trying to achieve &lt;BR /&gt;&lt;BR /&gt;I have a couple of servers in a list in a file so the for loop edits the file for each  server. &lt;BR /&gt;&lt;BR /&gt;Now FILE1 is the file in which the patterns are found &lt;BR /&gt;&lt;BR /&gt;Script &lt;BR /&gt;&lt;BR /&gt;newdate=`date`&lt;BR /&gt;for p in `cat servername`&lt;BR /&gt;&lt;BR /&gt;do &lt;BR /&gt;oldfile=`grep $p FILE1`&lt;BR /&gt;newfile= $p$newdate&lt;BR /&gt;&lt;BR /&gt;sed "s%${oldfile}%${newfile}%g" FILE1 &amp;gt; FILE2&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;cp FILE1 FILE.bck&lt;BR /&gt;mv FILE2 FILE1&lt;BR /&gt;&lt;BR /&gt;FILE 1 before the for loop &lt;BR /&gt;&lt;BR /&gt;CONTENT &lt;BR /&gt;servera.olddate&lt;BR /&gt;serverb.olddate&lt;BR /&gt;serverc.olddate&lt;BR /&gt;serverd.olddate&lt;BR /&gt;servere.olddate&lt;BR /&gt;Content&lt;BR /&gt;&lt;BR /&gt;What I want to see&lt;BR /&gt;&lt;BR /&gt;FILE 2&lt;BR /&gt;Content &lt;BR /&gt;servera.newdate&lt;BR /&gt;serverb.newdate&lt;BR /&gt;serverc.newdate&lt;BR /&gt;serverd.newdate&lt;BR /&gt;servere.olddate&lt;BR /&gt;Content&lt;BR /&gt;&lt;BR /&gt;I want the output to look like&lt;BR /&gt;&lt;BR /&gt;Now FILE1 has other content and I only need the multiple patterns changed but if I use a double &amp;gt;&amp;gt; it will direct all the contents over and over for each instance of the for loop&lt;BR /&gt;&lt;BR /&gt;aaaabbbb&lt;BR /&gt;ccccdddd&lt;BR /&gt;eeeeffff&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now say I need to change patterns aaaa and cccc to new paterns xxxx and yyyy so I perform the following &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Apr 2004 08:33:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259034#M888181</guid>
      <dc:creator>Stephen Kennedy_2</dc:creator>
      <dc:date>2004-04-26T08:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Multiple Strings on 1 file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259035#M888182</link>
      <description>You need to move the "mv" into the loop and the "cp" outside the loop:&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;newdate=`date +'%Y%m%d%H%M%S'`&lt;BR /&gt;cp FILE1 FILE.bck&lt;BR /&gt;for p in `cat servername`&lt;BR /&gt;do&lt;BR /&gt;   oldfile=`grep $p FILE1`&lt;BR /&gt;   newfile="${p}.${newdate}"&lt;BR /&gt;   sed "s%${oldfile}%${newfile}%g" FILE1 &amp;gt; FILE2&lt;BR /&gt;   mv FILE2 FILE1&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 26 Apr 2004 09:50:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259035#M888182</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2004-04-26T09:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Replace Multiple Strings on 1 file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259036#M888183</link>
      <description>or better yet, try this (SINGLE pass):&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;newdate=`date +'%Y%m%d%H%M%S'`&lt;BR /&gt;cp FILE1 FILE.bck&lt;BR /&gt;cat /dev/null &amp;gt;SED1&lt;BR /&gt;for p in `cat servername`&lt;BR /&gt;do&lt;BR /&gt;   oldfile=`grep $p FILE1`&lt;BR /&gt;   newfile="${p}.${newdate}"&lt;BR /&gt;   echo "s%${oldfile}%${newfile}%g" &amp;gt;&amp;gt;SED1&lt;BR /&gt;done&lt;BR /&gt;sed -f SED1 FILE1 &amp;gt; FILE2&lt;BR /&gt;mv FILE2 FILE1&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 26 Apr 2004 09:58:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-multiple-strings-on-1-file/m-p/3259036#M888183</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2004-04-26T09:58:26Z</dc:date>
    </item>
  </channel>
</rss>

