<?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 environment variables in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832668#M89264</link>
    <description>I don't think you can change ENV vars from awk; only read them.&lt;BR /&gt;&lt;BR /&gt;You could accomplish this by doing something like:&lt;BR /&gt;&lt;BR /&gt;Add: BEGIN{exitcode=0} to the awk code&lt;BR /&gt;&lt;BR /&gt;Change:&lt;BR /&gt;else if (NF &amp;gt; 20) {ENVIRON ["FIELD_ERR"]="1"} &lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;&lt;BR /&gt;else if (NF &amp;gt; 20) {exitcode=1} &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Add: END{exit exitcode} to the end of the awk script.&lt;BR /&gt;&lt;BR /&gt;Then in the shell script portion right after the awk call:&lt;BR /&gt;  export FIELD_ERR=$?&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 24 Oct 2002 14:20:22 GMT</pubDate>
    <dc:creator>Tom Danzig</dc:creator>
    <dc:date>2002-10-24T14:20:22Z</dc:date>
    <item>
      <title>AWK environment variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832664#M89260</link>
      <description>Hi people,&lt;BR /&gt;&lt;BR /&gt;I am trying to figure out how to set a variable in the middle of an awk statement i.e.&lt;BR /&gt;&lt;BR /&gt;#set a variable that I need &lt;BR /&gt;#to reference within an awk &lt;BR /&gt;#statement (called FIELD_ERR)&lt;BR /&gt;FIELD_ERR=0&lt;BR /&gt;for &lt;BLAH blah=""&gt;&lt;BR /&gt; do&lt;BR /&gt;  while read x&lt;BR /&gt;  do&lt;BR /&gt;   x=$(echo $x | awk -F"|" '{&lt;BR /&gt;        if (NF == 20) {printf &lt;BLAH&gt; }&lt;BR /&gt;#try and change the variable here&lt;BR /&gt;        else if (NF &amp;gt; 20) {ENVIRON ["FIELD_ERR"] = "1"}&lt;BR /&gt;        else {print $0} }')&lt;BR /&gt;   echo $x &amp;gt;&amp;gt; ${db02file}.out&lt;BR /&gt;  done &amp;lt; $db02file&lt;BR /&gt;&lt;BR /&gt;# but this is where I can't reference it!&lt;BR /&gt;#if I print it, it is still 0 despite the&lt;BR /&gt;#condition above being met&lt;BR /&gt;  if [ $FIELD_ERR -eq 1 ]&lt;BR /&gt;  then&lt;BR /&gt;  echo "reached"&lt;BR /&gt;  fi&lt;BR /&gt; done&lt;BR /&gt;&lt;BR /&gt;echo $FIELD_ERR&lt;BR /&gt;&lt;BR /&gt;any help would be appreciated with regards to referencing variables declared outside an awk statement, that are then used inside it!&lt;BR /&gt;&lt;BR /&gt;let me know if this is not clear!&lt;BR /&gt;&lt;BR /&gt;cheers&lt;BR /&gt;John&lt;/BLAH&gt;&lt;/BLAH&gt;</description>
      <pubDate>Thu, 24 Oct 2002 13:03:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832664#M89260</guid>
      <dc:creator>u856100</dc:creator>
      <dc:date>2002-10-24T13:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: AWK environment variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832665#M89261</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I think that you can't do it this way ... when you use a awk command, it forks a new process, so you will never be able to access any env var in this environment from its parent process. ENVIRON can only be used to READ variables from env.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Jean-Louis.</description>
      <pubDate>Thu, 24 Oct 2002 13:08:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832665#M89261</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2002-10-24T13:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: AWK environment variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832666#M89262</link>
      <description>What you are trying to do is&lt;BR /&gt;have a child change the environment of a parent process. That can't be done - the direction of data flow is one way - parent to child. About the only way to do something like this is to have the child process write to a file (or a named pipe) and then the parent could read the file (or pipe) and set the variable.&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Oct 2002 13:12:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832666#M89262</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-10-24T13:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: AWK environment variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832667#M89263</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;Perhaps try :&lt;BR /&gt;&lt;BR /&gt;ERRFILE=/tmp/awk$$&lt;BR /&gt;FIELD_ERR=0 &lt;BR /&gt;for &lt;BLAH blah=""&gt; &lt;BR /&gt;do &lt;BR /&gt;while read x &lt;BR /&gt;do &lt;BR /&gt;x=$(echo $x | awk -v errfile="$ERRFILE" -F"|" '{ &lt;BR /&gt;if (NF == 20) {printf &lt;BLAH&gt; } &lt;BR /&gt;#try and change the variable here &lt;BR /&gt;else if (NF &amp;gt; 20) {system("touch " errfile) } &lt;BR /&gt;else {print $0} }') &lt;BR /&gt;echo $x &amp;gt;&amp;gt; ${db02file}.out &lt;BR /&gt;done &amp;lt; $db02file &lt;BR /&gt;&lt;BR /&gt;if [ -r "$ERRFILE" ] &lt;BR /&gt;then &lt;BR /&gt;echo "reached" &lt;BR /&gt;fi &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Jean-Louis.&lt;/BLAH&gt;&lt;/BLAH&gt;</description>
      <pubDate>Thu, 24 Oct 2002 13:27:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832667#M89263</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2002-10-24T13:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: AWK environment variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832668#M89264</link>
      <description>I don't think you can change ENV vars from awk; only read them.&lt;BR /&gt;&lt;BR /&gt;You could accomplish this by doing something like:&lt;BR /&gt;&lt;BR /&gt;Add: BEGIN{exitcode=0} to the awk code&lt;BR /&gt;&lt;BR /&gt;Change:&lt;BR /&gt;else if (NF &amp;gt; 20) {ENVIRON ["FIELD_ERR"]="1"} &lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;&lt;BR /&gt;else if (NF &amp;gt; 20) {exitcode=1} &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Add: END{exit exitcode} to the end of the awk script.&lt;BR /&gt;&lt;BR /&gt;Then in the shell script portion right after the awk call:&lt;BR /&gt;  export FIELD_ERR=$?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 24 Oct 2002 14:20:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832668#M89264</guid>
      <dc:creator>Tom Danzig</dc:creator>
      <dc:date>2002-10-24T14:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: AWK environment variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832669#M89265</link>
      <description>Try use awk -v to set a variable.</description>
      <pubDate>Fri, 25 Oct 2002 00:33:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-environment-variables/m-p/2832669#M89265</guid>
      <dc:creator>Chia-Wei</dc:creator>
      <dc:date>2002-10-25T00:33:50Z</dc:date>
    </item>
  </channel>
</rss>

