<?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: File content checking and replacing it! in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/file-content-checking-and-replacing-it/m-p/4871627#M859161</link>
    <description>For the replacing you simply can use sed:&lt;BR /&gt;sed 's|&lt;SUBID&gt;".*"&lt;/SUBID&gt;|&lt;SUBID&gt;"9999"&lt;/SUBID&gt;'&lt;BR /&gt;&lt;BR /&gt;But since you also want the old value in a variable, it gets trickier.&lt;BR /&gt;&lt;BR /&gt;You could do something like this:&lt;BR /&gt;&lt;BR /&gt;oldvalues=$(sed -n '/&lt;SUBID&gt;".*"&amp;lt;\/SUBID&amp;gt;/s|.*&lt;SUBID&gt;"\(.*\)"&lt;/SUBID&gt;.*|\1|p' input)&lt;BR /&gt;sed 's|&lt;SUBID&gt;".*"&lt;/SUBID&gt;|&lt;SUBID&gt;"9999"&lt;/SUBID&gt;|' input &amp;gt; output&lt;BR /&gt;&lt;BR /&gt;This means, of course, that you run twice through the input file with sed...&lt;/SUBID&gt;</description>
    <pubDate>Mon, 22 Nov 2004 02:49:10 GMT</pubDate>
    <dc:creator>Elmar P. Kolkman</dc:creator>
    <dc:date>2004-11-22T02:49:10Z</dc:date>
    <item>
      <title>File content checking and replacing it!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/file-content-checking-and-replacing-it/m-p/4871625#M859159</link>
      <description>I have a file which contain the line&lt;BR /&gt;...&lt;BR /&gt;...&lt;BR /&gt;&lt;SUBID&gt;"-"&lt;/SUBID&gt;&lt;BR /&gt;...&lt;BR /&gt;...&lt;BR /&gt;I need to get the "-" part to be passed to a variable ad subsequently replaced it by "9999". How can i get it in a single command?&lt;BR /&gt;&lt;BR /&gt;Maximum points for correct reply!</description>
      <pubDate>Mon, 22 Nov 2004 01:57:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/file-content-checking-and-replacing-it/m-p/4871625#M859159</guid>
      <dc:creator>Pando</dc:creator>
      <dc:date>2004-11-22T01:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: File content checking and replacing it!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/file-content-checking-and-replacing-it/m-p/4871626#M859160</link>
      <description>A variable to the changing process, or to the calling shell?&lt;BR /&gt;&lt;BR /&gt;# perl -pi -e's{&lt;SUBID&gt;"(.*?)"&lt;/SUBID&gt;}{&lt;SUBID&gt;"9999"&lt;/SUBID&gt;} and $perl_var = $1' file&lt;BR /&gt;&lt;BR /&gt;would change the content of file and have the variable available just after the change in perl as $perl_var&lt;BR /&gt;&lt;BR /&gt;If it is only one line that is changed, and you want to promote the variable to the shell, you need to catch it and set it&lt;BR /&gt;&lt;BR /&gt;# MY_VAR=`(perl -pi -e's{&amp;lt;(SUBID)&amp;gt;"(.*?)"}{&amp;lt;$1&amp;gt;"9999"} and print STDERR "$2\n"' file) 2&amp;gt;&amp;amp;1`&lt;BR /&gt;&lt;BR /&gt;As a proof of concept:&lt;BR /&gt;--8&amp;lt;---&lt;BR /&gt;sh-2.05b$ MY_VAR=2&lt;BR /&gt;sh-2.05b$ echo $MY_VAR&lt;BR /&gt;2&lt;BR /&gt;sh-2.05b$ cat file&lt;BR /&gt;Line 1&lt;BR /&gt;&lt;BR /&gt;Line 3&lt;BR /&gt;&lt;SUBID&gt;"1234"&lt;/SUBID&gt;&lt;BR /&gt;&lt;BR /&gt;Line 6&lt;BR /&gt;sh-2.05b$ MY_VAR=`(perl -pi -e's{&amp;lt;(SUBID)&amp;gt;"(.*?)"}{&amp;lt;$1&amp;gt;"9999"} and print STDERR "$2\n"' file) 2&amp;gt;&amp;amp;1`&lt;BR /&gt;sh-2.05b$ echo $MY_VAR&lt;BR /&gt;1234&lt;BR /&gt;sh-2.05b$ cat file&lt;BR /&gt;Line 1&lt;BR /&gt;&lt;BR /&gt;Line 3&lt;BR /&gt;&lt;SUBID&gt;"9999"&lt;/SUBID&gt;&lt;BR /&gt;&lt;BR /&gt;Line 6&lt;BR /&gt;sh-2.05b$&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Mon, 22 Nov 2004 02:10:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/file-content-checking-and-replacing-it/m-p/4871626#M859160</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-11-22T02:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: File content checking and replacing it!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/file-content-checking-and-replacing-it/m-p/4871627#M859161</link>
      <description>For the replacing you simply can use sed:&lt;BR /&gt;sed 's|&lt;SUBID&gt;".*"&lt;/SUBID&gt;|&lt;SUBID&gt;"9999"&lt;/SUBID&gt;'&lt;BR /&gt;&lt;BR /&gt;But since you also want the old value in a variable, it gets trickier.&lt;BR /&gt;&lt;BR /&gt;You could do something like this:&lt;BR /&gt;&lt;BR /&gt;oldvalues=$(sed -n '/&lt;SUBID&gt;".*"&amp;lt;\/SUBID&amp;gt;/s|.*&lt;SUBID&gt;"\(.*\)"&lt;/SUBID&gt;.*|\1|p' input)&lt;BR /&gt;sed 's|&lt;SUBID&gt;".*"&lt;/SUBID&gt;|&lt;SUBID&gt;"9999"&lt;/SUBID&gt;|' input &amp;gt; output&lt;BR /&gt;&lt;BR /&gt;This means, of course, that you run twice through the input file with sed...&lt;/SUBID&gt;</description>
      <pubDate>Mon, 22 Nov 2004 02:49:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/file-content-checking-and-replacing-it/m-p/4871627#M859161</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-11-22T02:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: File content checking and replacing it!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/file-content-checking-and-replacing-it/m-p/4871628#M859162</link>
      <description>Thanks for that quick reply.&lt;BR /&gt;</description>
      <pubDate>Mon, 22 Nov 2004 03:40:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/file-content-checking-and-replacing-it/m-p/4871628#M859162</guid>
      <dc:creator>Pando</dc:creator>
      <dc:date>2004-11-22T03:40:53Z</dc:date>
    </item>
  </channel>
</rss>

