<?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: How to update a file content from a KShell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445540#M729002</link>
    <description>Just to be different:&lt;BR /&gt;&lt;BR /&gt;IFSSAVE="$IFS"&lt;BR /&gt;IFS="="&lt;BR /&gt;while read VAR VALUE&lt;BR /&gt;do&lt;BR /&gt;if [ "$VAR" = "{variable you want to change"} ]&lt;BR /&gt;then&lt;BR /&gt;     echo "$VAR={new value}" &amp;gt;&amp;gt; tmpfile&lt;BR /&gt;else&lt;BR /&gt;     echo "$VAR=$VALUE" &amp;gt;&amp;gt; tmpfile&lt;BR /&gt;fi&lt;BR /&gt;done &amp;lt; file&lt;BR /&gt;mv tmpfile file&lt;BR /&gt;&lt;BR /&gt;Now, the sed really makes more sense, and sed is a great thing to become familiar with, but it is sometimes easier to modify/maintain a script if you  are more familiar with exactly what it does, so I figured I would give you this alternative.&lt;BR /&gt;&lt;BR /&gt;But play around with sed, too.  It will be worth your time.</description>
    <pubDate>Fri, 15 Sep 2000 13:46:54 GMT</pubDate>
    <dc:creator>Alan Riggs</dc:creator>
    <dc:date>2000-09-15T13:46:54Z</dc:date>
    <item>
      <title>How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445536#M728998</link>
      <description>I have a parameter file which contains severail variables declaration. I want to build a ksh script which read that file, find the proper variable I look for and change is value.&lt;BR /&gt;How can I do that ?&lt;BR /&gt;--------------&lt;BR /&gt;Example:&lt;BR /&gt;(content of param.var)&lt;BR /&gt;LOCAL_VAR1="ABC"&lt;BR /&gt;LOCAL_VAR2="TOTO"&lt;BR /&gt;LOCAL_VAR3=25&lt;BR /&gt;&lt;BR /&gt;-&amp;gt; Must change LOCAL_VAR2 to "TEST" ?&lt;BR /&gt;</description>
      <pubDate>Thu, 14 Sep 2000 21:02:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445536#M728998</guid>
      <dc:creator>Admin.SIF</dc:creator>
      <dc:date>2000-09-14T21:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445537#M728999</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;# cat master_script | sed s/LOCAL_VAR2=\"TOTO\"/LOCAL_VAR2=\"XXXX\"/g &amp;gt; new_script&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 14 Sep 2000 21:22:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445537#M728999</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2000-09-14T21:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445538#M729000</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;# cat master_script |sed /LOCAL_VAR2=\"TOTO\"/LOCAL_VAR2=\"XXXX\"/g &amp;gt; new_script&lt;BR /&gt;&lt;BR /&gt;Note the backslashes to escape the quote marks in your master_script.&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 14 Sep 2000 21:24:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445538#M729000</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2000-09-14T21:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445539#M729001</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;you could also do this:&lt;BR /&gt;&lt;BR /&gt;awk -F= '{&lt;BR /&gt;if($1 == "LOCAL_VAR2")&lt;BR /&gt;  print $1 "=" "\"TEST\""&lt;BR /&gt;else&lt;BR /&gt;  print $1 "=" $2&lt;BR /&gt;}' param.var &amp;gt;param_tmp.var&lt;BR /&gt;mv param_tmp.var param.var&lt;BR /&gt;&lt;BR /&gt;For multiple choices add some else if (...)&lt;BR /&gt;statements before the else statement.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Andrew</description>
      <pubDate>Fri, 15 Sep 2000 06:35:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445539#M729001</guid>
      <dc:creator>Andreas Voss</dc:creator>
      <dc:date>2000-09-15T06:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445540#M729002</link>
      <description>Just to be different:&lt;BR /&gt;&lt;BR /&gt;IFSSAVE="$IFS"&lt;BR /&gt;IFS="="&lt;BR /&gt;while read VAR VALUE&lt;BR /&gt;do&lt;BR /&gt;if [ "$VAR" = "{variable you want to change"} ]&lt;BR /&gt;then&lt;BR /&gt;     echo "$VAR={new value}" &amp;gt;&amp;gt; tmpfile&lt;BR /&gt;else&lt;BR /&gt;     echo "$VAR=$VALUE" &amp;gt;&amp;gt; tmpfile&lt;BR /&gt;fi&lt;BR /&gt;done &amp;lt; file&lt;BR /&gt;mv tmpfile file&lt;BR /&gt;&lt;BR /&gt;Now, the sed really makes more sense, and sed is a great thing to become familiar with, but it is sometimes easier to modify/maintain a script if you  are more familiar with exactly what it does, so I figured I would give you this alternative.&lt;BR /&gt;&lt;BR /&gt;But play around with sed, too.  It will be worth your time.</description>
      <pubDate>Fri, 15 Sep 2000 13:46:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445540#M729002</guid>
      <dc:creator>Alan Riggs</dc:creator>
      <dc:date>2000-09-15T13:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445541#M729003</link>
      <description>Just to be different:&lt;BR /&gt;&lt;BR /&gt;IFSSAVE="$IFS"&lt;BR /&gt;IFS="="&lt;BR /&gt;while read VAR VALUE&lt;BR /&gt;do&lt;BR /&gt;if [ "$VAR" = "{variable you want to change"} ]&lt;BR /&gt;then&lt;BR /&gt;     echo "$VAR={new value}" &amp;gt;&amp;gt; tmpfile&lt;BR /&gt;else&lt;BR /&gt;     echo "$VAR=$VALUE" &amp;gt;&amp;gt; tmpfile&lt;BR /&gt;fi&lt;BR /&gt;done &amp;lt; file&lt;BR /&gt;mv tmpfile file&lt;BR /&gt;&lt;BR /&gt;Now, the sed really makes more sense, and sed is a great thing to become familiar with, but it is sometimes easier to modify/maintain a script if you  are more familiar with exactly what it does, so I figured I would give you this alternative.&lt;BR /&gt;&lt;BR /&gt;But play around with sed, too.  It will be worth your time.</description>
      <pubDate>Fri, 15 Sep 2000 13:49:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445541#M729003</guid>
      <dc:creator>Alan Riggs</dc:creator>
      <dc:date>2000-09-15T13:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445542#M729004</link>
      <description>Hi.&lt;BR /&gt;&lt;BR /&gt;I would use&lt;BR /&gt;&lt;BR /&gt;cat param.var|sed 'LOCAL_VAR2/TEST' &amp;gt;newparam&lt;BR /&gt;&lt;BR /&gt;I hope this helps&lt;BR /&gt;&lt;BR /&gt;Dave</description>
      <pubDate>Sun, 17 Sep 2000 16:38:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445542#M729004</guid>
      <dc:creator>Dave Walley</dc:creator>
      <dc:date>2000-09-17T16:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445543#M729005</link>
      <description>Yet another way to do it, with the advantage that you don't need any temporary files.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;# Change paramfile eg. $HOME/params&lt;BR /&gt;#&lt;BR /&gt;cat - &amp;lt;&amp;lt; EOF | ed -s $HOME/params&lt;BR /&gt;1,$ s:LOCAL_VAR2="TOTO":LOCAL_VAR2="TEST":&lt;BR /&gt;w&lt;BR /&gt;q&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;Could of course be made more generic, by passing name of parameter file and which parameter to change as arguments.</description>
      <pubDate>Mon, 18 Sep 2000 11:04:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445543#M729005</guid>
      <dc:creator>Tommy Palo</dc:creator>
      <dc:date>2000-09-18T11:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445544#M729006</link>
      <description>I'm not sure what you are trying to achieve here. If you want to edit the param file from within a script then you can use 'ex' (a command line version of vi). Example:-&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;ex param.var &amp;lt;&lt;EOD&gt;&lt;/EOD&gt;/LOCAL_VAR2&lt;BR /&gt;s/TOTO/TEST/&lt;BR /&gt;wq!&lt;BR /&gt;EOD&lt;BR /&gt;&lt;BR /&gt;If you want to get the values for your variables into the script then you can just 'dot' the file then maybe reassign any variables that you want to override. For example:-&lt;BR /&gt;&lt;BR /&gt;. param.var&lt;BR /&gt;LOCALVAR2=TEST&lt;BR /&gt;&lt;BR /&gt;If you are trying to do anything else, please supply some more details.</description>
      <pubDate>Mon, 18 Sep 2000 11:57:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445544#M729006</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2000-09-18T11:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to update a file content from a KShell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445545#M729007</link>
      <description>Finaly, I use the sed command and it works correctly.&lt;BR /&gt;&lt;BR /&gt;Thanks for your help.</description>
      <pubDate>Mon, 18 Sep 2000 13:02:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-update-a-file-content-from-a-kshell-script/m-p/2445545#M729007</guid>
      <dc:creator>Admin.SIF</dc:creator>
      <dc:date>2000-09-18T13:02:53Z</dc:date>
    </item>
  </channel>
</rss>

