<?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: Awk help to process a resource file by a shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550945#M702192</link>
    <description>Rod, I think you missed the part about matching the script_name...&lt;BR /&gt;&lt;BR /&gt;Some of the other guys suggest sourcing in your resource file(s) directly, which will work fine, assuming you have the capability to make this change (it's a manually generated file, and not generated by some closed-source app).  &lt;BR /&gt;&lt;BR /&gt;However, this mechanism assumes a level of trust that noone has put malware-type commands into the resource file(s), as they would be happily executed with the permissions of the user running the script.  Of course, if the write permissions on the resource file(s) are as restrictive or stronger than execute permissions on the script, then this isn't a big deal.&lt;BR /&gt;&lt;BR /&gt;Just something to think about...&lt;BR /&gt;&lt;BR /&gt;--Greg</description>
    <pubDate>Tue, 24 May 2005 15:20:32 GMT</pubDate>
    <dc:creator>Greg Vaidman</dc:creator>
    <dc:date>2005-05-24T15:20:32Z</dc:date>
    <item>
      <title>Awk help to process a resource file by a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550941#M702188</link>
      <description>Greetings to all awk and sed gurus!&lt;BR /&gt;&lt;BR /&gt;I have a general resource file of the following format that must be read and sourced by several shell scripts:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Loading.NRT_DAYS=1&lt;BR /&gt;Loading.POLLING_INTERVAL=5&lt;BR /&gt;#Loading.POLLING_INTERVAL=30&lt;BR /&gt;Loading.MASK=*&lt;BR /&gt;&lt;BR /&gt;Running.NRT_DAYS=1&lt;BR /&gt;Running.POLLING_INTERVAL=5&lt;BR /&gt;#Running.POLLING_INTERVAL=30&lt;BR /&gt;&lt;BR /&gt;…&lt;BR /&gt;&lt;BR /&gt;Where:&lt;BR /&gt; Line beginning with #, are comments&lt;BR /&gt; Each entry has the format: Script_name.variable_name=value&lt;BR /&gt;&lt;BR /&gt;I want to write within my shell script an awk command to read and parse this file. For each line matching the script name, it will:&lt;BR /&gt;export variable_name=value&lt;BR /&gt;…&lt;BR /&gt;&lt;BR /&gt;I am quiet proficient in shell scripting and tha kind of parsing is complex because * can be a value…&lt;BR /&gt;I believe the parsing can be achieved by a simple awk command…&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Any help/suggestion is highly appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance for your help,&lt;BR /&gt; &lt;BR /&gt;Kind Regards,&lt;BR /&gt; &lt;BR /&gt;Rui</description>
      <pubDate>Tue, 24 May 2005 13:45:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550941#M702188</guid>
      <dc:creator>Rui Vilao</dc:creator>
      <dc:date>2005-05-24T13:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help to process a resource file by a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550942#M702189</link>
      <description>Try this-&lt;BR /&gt; &lt;BR /&gt;awk -F= '!/#/{print "export " $1 "=''" $2 "''" }' &lt;INPUTFILE&gt;/tmp/export$$&lt;BR /&gt;. /tmp/export$$&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills&lt;/INPUTFILE&gt;</description>
      <pubDate>Tue, 24 May 2005 14:23:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550942#M702189</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2005-05-24T14:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help to process a resource file by a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550943#M702190</link>
      <description>why parse a file at all?&lt;BR /&gt;&lt;BR /&gt;create a seperate file for loading, running, etc.; put the files all in the same directory&lt;BR /&gt;&lt;BR /&gt;and instead of lines like:&lt;BR /&gt;Running.NRT_DAYS=1&lt;BR /&gt;&lt;BR /&gt;make them like this:&lt;BR /&gt;export NRT_DAYS=1&lt;BR /&gt;&lt;BR /&gt;then exporting the variables is as easy as:&lt;BR /&gt;&lt;BR /&gt;. $dirWhereFilesAre/$yourScriptName&lt;BR /&gt;&lt;BR /&gt;just a suggestion</description>
      <pubDate>Tue, 24 May 2005 14:30:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550943#M702190</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-05-24T14:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help to process a resource file by a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550944#M702191</link>
      <description>Hi,&lt;BR /&gt;no gurus around here...&lt;BR /&gt;But the attached script may serve as a starting point. Try it with your input file as $1.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
      <pubDate>Tue, 24 May 2005 14:41:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550944#M702191</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2005-05-24T14:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help to process a resource file by a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550945#M702192</link>
      <description>Rod, I think you missed the part about matching the script_name...&lt;BR /&gt;&lt;BR /&gt;Some of the other guys suggest sourcing in your resource file(s) directly, which will work fine, assuming you have the capability to make this change (it's a manually generated file, and not generated by some closed-source app).  &lt;BR /&gt;&lt;BR /&gt;However, this mechanism assumes a level of trust that noone has put malware-type commands into the resource file(s), as they would be happily executed with the permissions of the user running the script.  Of course, if the write permissions on the resource file(s) are as restrictive or stronger than execute permissions on the script, then this isn't a big deal.&lt;BR /&gt;&lt;BR /&gt;Just something to think about...&lt;BR /&gt;&lt;BR /&gt;--Greg</description>
      <pubDate>Tue, 24 May 2005 15:20:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550945#M702192</guid>
      <dc:creator>Greg Vaidman</dc:creator>
      <dc:date>2005-05-24T15:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help to process a resource file by a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550946#M702193</link>
      <description>To add confusion to this is shell environment space protection.&lt;BR /&gt;&lt;BR /&gt;Which shell are you going to use?&lt;BR /&gt;&lt;BR /&gt;Generally you could use something like Rodney's solution (expanding upon that a little) in `` shell-execution, but some shells might not allow it.</description>
      <pubDate>Tue, 24 May 2005 18:49:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550946#M702193</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2005-05-24T18:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help to process a resource file by a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550947#M702194</link>
      <description>$ cat myscript&lt;BR /&gt;!/usr/bin/awk&lt;BR /&gt;FILENAME=$1&lt;BR /&gt;awk -F'.' `&lt;BR /&gt;BEGIN { script_name=$FILENAME }&lt;BR /&gt;{ if($1==script_name) 'print "export "$2' }&lt;BR /&gt;`&lt;BR /&gt;&lt;BR /&gt;$ myscript &amp;lt;script name&amp;gt;&lt;BR /&gt;&lt;BR /&gt;I am not sure if the awk uses forward quotes or single quotes for instruction. You might try it. Sorry, I haven't tested this program. But am sure it will help you in writing one.</description>
      <pubDate>Tue, 31 May 2005 08:26:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550947#M702194</guid>
      <dc:creator>Amit Agarwal_1</dc:creator>
      <dc:date>2005-05-31T08:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help to process a resource file by a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550948#M702195</link>
      <description>Okay, I got access to a system. Here is the solution&lt;BR /&gt;&lt;BR /&gt;$ cat myscript&lt;BR /&gt;FILENAME=$1&lt;BR /&gt;awk -v script_name=$FILENAME -F "." '&lt;BR /&gt;{ if($1==script_name) print "export " $2 }&lt;BR /&gt;'&amp;lt; resource_file&lt;BR /&gt;&lt;BR /&gt;Output:&lt;BR /&gt;========&lt;BR /&gt;$ ./myscript Loading      &lt;BR /&gt;export NRT_DAYS=1&lt;BR /&gt;export POLLING_INTERVAL=5&lt;BR /&gt;export MASK=*&lt;BR /&gt;$ ./myscript Running&lt;BR /&gt;export NRT_DAYS=1&lt;BR /&gt;export POLLING_INTERVAL=5&lt;BR /&gt;&lt;BR /&gt;I hope this helps.&lt;BR /&gt;&lt;BR /&gt;Amit&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Jun 2005 00:55:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550948#M702195</guid>
      <dc:creator>Amit Agarwal_1</dc:creator>
      <dc:date>2005-06-01T00:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Awk help to process a resource file by a shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550949#M702196</link>
      <description>For Example, Details are in resource file as,&lt;BR /&gt;&lt;BR /&gt;resource.log&lt;BR /&gt;Loading.NRT_DAYS=1&lt;BR /&gt;Loading.POLLING_INTERVAL=5&lt;BR /&gt;#Loading.POLLING_INTERVAL=30&lt;BR /&gt;Loading.MASK=*&lt;BR /&gt;&lt;BR /&gt;Running.NRT_DAYS=1&lt;BR /&gt;Running.POLLING_INTERVAL=5&lt;BR /&gt;#Running.POLLING_INTERVAL=30&lt;BR /&gt;&lt;BR /&gt;Then, You can try in each script file as,&lt;BR /&gt;&lt;BR /&gt;---- Loading file ---&lt;BR /&gt;File=$(basename $0 | cut -d"." -f1)&lt;BR /&gt;for var in `grep $FILE resource.log | cut -d"." -f2-`&lt;BR /&gt;do&lt;BR /&gt;   variable=$(echo $var | cut -d"=" -f1)&lt;BR /&gt;   value=$(echo $var | cut -d"=" -f2)&lt;BR /&gt;   export $variable=$value&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Keep the same in all required files.&lt;BR /&gt;&lt;BR /&gt;hth.&lt;BR /&gt;   &lt;BR /&gt;</description>
      <pubDate>Wed, 01 Jun 2005 04:41:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-help-to-process-a-resource-file-by-a-shell-script/m-p/3550949#M702196</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-06-01T04:41:33Z</dc:date>
    </item>
  </channel>
</rss>

