<?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 variables in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912666#M107680</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;here a little correction to curt's answer:&lt;BR /&gt;&lt;BR /&gt;cat yourfile | awk -F"|" ' &lt;BR /&gt;/header/ {x=$2;print $0;next;} &lt;BR /&gt;/footer/ {sub("|" $2 "|","|" x "|", $0);print $0;next;} &lt;BR /&gt;{print $0;}'&lt;BR /&gt;&lt;BR /&gt;Regards</description>
    <pubDate>Wed, 26 Feb 2003 10:03:28 GMT</pubDate>
    <dc:creator>Andreas Voss</dc:creator>
    <dc:date>2003-02-26T10:03:28Z</dc:date>
    <item>
      <title>AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912661#M107675</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;does anyone know how to reference a variable in awk, i.e.&lt;BR /&gt;&lt;BR /&gt;I want to pick up a specified column from row1 and use it for the output of row2&lt;BR /&gt;&lt;BR /&gt;say we have  :&lt;BR /&gt;header|1|&lt;BR /&gt;a|b|c|d|e|f|&lt;BR /&gt;footer|0|&lt;BR /&gt;&lt;BR /&gt;and I wanted to change this to :&lt;BR /&gt;header|1|&lt;BR /&gt;a|b|c|d|e|f|&lt;BR /&gt;footer|1|&lt;BR /&gt;&lt;BR /&gt;but the new footer variable is picked up from the header numeric (in this case 1)&lt;BR /&gt;&lt;BR /&gt;so the following :&lt;BR /&gt;header|5|&lt;BR /&gt;a|b|c|d|e|f|&lt;BR /&gt;footer|2|&lt;BR /&gt;&lt;BR /&gt;needs to be :&lt;BR /&gt;header|5|&lt;BR /&gt;a|b|c|d|e|f|&lt;BR /&gt;footer|5|&lt;BR /&gt;&lt;BR /&gt;thanks in advance gurus!&lt;BR /&gt;&lt;BR /&gt;John&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Feb 2003 14:45:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912661#M107675</guid>
      <dc:creator>u856100</dc:creator>
      <dc:date>2003-02-25T14:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912662#M107676</link>
      <description>Hi John:&lt;BR /&gt;&lt;BR /&gt;'substr' is suited for this.  For example:&lt;BR /&gt;&lt;BR /&gt;# echo "header|1|" | awk '{X=substr($0,8,1);print X}'&lt;BR /&gt;&lt;BR /&gt;...would print:&lt;BR /&gt;&lt;BR /&gt;1&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 25 Feb 2003 14:55:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912662#M107676</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2003-02-25T14:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912663#M107677</link>
      <description>Highly recommend the book "The AWK Programming Language" by Aho, Kernighan, Weinberger.  One of the smallest, yet perfectly consise manuals I've ever seen.  Addison-Wesley Publishing Company.&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Feb 2003 21:16:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912663#M107677</guid>
      <dc:creator>Fred Martin_1</dc:creator>
      <dc:date>2003-02-25T21:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912664#M107678</link>
      <description>cat yourfile | awk -F"|" '&lt;BR /&gt;/header/ {x=$2;print $0;next;}&lt;BR /&gt;/footer/ {sub($2,x);print $0;next;}&lt;BR /&gt;{print $0;}'</description>
      <pubDate>Tue, 25 Feb 2003 23:34:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912664#M107678</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-02-25T23:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912665#M107679</link>
      <description>Hi Curt,&lt;BR /&gt;&lt;BR /&gt;I can't get this to work as its trying to pick up the $2 entry for the footer string and not the header string&lt;BR /&gt;&lt;BR /&gt;I know by default, sub() uses $0 if a third parameter is ommitted.</description>
      <pubDate>Wed, 26 Feb 2003 09:05:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912665#M107679</guid>
      <dc:creator>u856100</dc:creator>
      <dc:date>2003-02-26T09:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912666#M107680</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;here a little correction to curt's answer:&lt;BR /&gt;&lt;BR /&gt;cat yourfile | awk -F"|" ' &lt;BR /&gt;/header/ {x=$2;print $0;next;} &lt;BR /&gt;/footer/ {sub("|" $2 "|","|" x "|", $0);print $0;next;} &lt;BR /&gt;{print $0;}'&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Wed, 26 Feb 2003 10:03:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912666#M107680</guid>
      <dc:creator>Andreas Voss</dc:creator>
      <dc:date>2003-02-26T10:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912667#M107681</link>
      <description>Hi John,&lt;BR /&gt;&lt;BR /&gt;This works for me, and you cut out a process by not using cat/pipe:&lt;BR /&gt;&lt;BR /&gt;awk -F\| '/header/{x=$2}/footer/{sub($2,x)}{print}' yourfile&lt;BR /&gt;&lt;BR /&gt;rgds, Robin</description>
      <pubDate>Wed, 26 Feb 2003 10:22:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912667#M107681</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2003-02-26T10:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912668#M107682</link>
      <description>all, thanks again for your cotinous replies.&lt;BR /&gt;&lt;BR /&gt;I can simulate curts example, but I am having problems applying to a specific case. The full extent of what I am trying to do is as follows :&lt;BR /&gt;&lt;BR /&gt;original file&lt;BR /&gt;-------------&lt;BR /&gt;ZHD|MDN0980268|D0215001|R|EMEB|X|BGAS|20030220114355|FORMF||OPER|&lt;BR /&gt;490|1100009199347|0|0|1|||||||METER MOVED OUTSIDE&lt;BR /&gt;ZPT|3|1111379456&lt;BR /&gt;&lt;BR /&gt;I want to change into this&lt;BR /&gt;--------------------------&lt;BR /&gt;ZHV|MDN0980268|D0215001|R|EMEB|X|BGAS|20030220114355|FORMF|||OPER|&lt;BR /&gt;490|1100009199347|0|0|1|||||||METER MOVED OUTSIDE|&lt;BR /&gt;ZPT|MDN0980268|1||1|20030224000001|&lt;BR /&gt;&lt;BR /&gt;But the script I have :&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;gives me this :&lt;BR /&gt;ZHV|MDN0980268|D0215001|R|EMEB|X|BGAS|20030220114355|FORMF|||OPER|&lt;BR /&gt;490|1100009199347|0|0|1|||||||METER MOVED OUTSIDE|&lt;BR /&gt;ZPT|1|1||1|20030224000001|&lt;BR /&gt;&lt;BR /&gt;I don't understand why the second pipe delimitted field in the last column is '1' and not 'MDN0980268'&lt;BR /&gt;&lt;BR /&gt;yours in confusion&lt;BR /&gt;John&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Feb 2003 10:46:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912668#M107682</guid>
      <dc:creator>u856100</dc:creator>
      <dc:date>2003-02-26T10:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912669#M107683</link>
      <description>please ignore the extra carriage returns after the first row.&lt;BR /&gt;&lt;BR /&gt;thanks</description>
      <pubDate>Wed, 26 Feb 2003 10:48:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912669#M107683</guid>
      <dc:creator>u856100</dc:creator>
      <dc:date>2003-02-26T10:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912670#M107684</link>
      <description>might be useful if I included the script (doh!)&lt;BR /&gt;&lt;BR /&gt;for i in `ls n098*`&lt;BR /&gt;do&lt;BR /&gt;awk -F"|" '&lt;BR /&gt;$1 ~ /^ZHD$/ {x=$2;printf("ZHV|%s|%s|%s|%s|%s|%s|%s|%s|%s||%s|\n",$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)}&lt;BR /&gt;$1 ~ /^ZPT$/ {print "ZPT|"sub($2,x)"|1||1|20030224000001|"}&lt;BR /&gt;$1 ~ /^490$/ {print $0"|"}' $i &amp;gt; /data/archive2/jb/formfill_new/$i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Feb 2003 10:50:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912670#M107684</guid>
      <dc:creator>u856100</dc:creator>
      <dc:date>2003-02-26T10:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: AWK variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912671#M107685</link>
      <description>Hi John,&lt;BR /&gt;&lt;BR /&gt;The "1" that you are seeing is the return value from the sub function.  You should do the substitution before printing, or simply put x in the print statement directly e.g.&lt;BR /&gt;&lt;BR /&gt;awk -F"|" '&lt;BR /&gt;        $1 ~ /^ZHD$/ {x=$2;printf("ZHV|%s|%s|%s|%s|%s|%s|%s|%s|%s||%s|\n",$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)}&lt;BR /&gt;        $1 ~ /^ZPT$/ {print "ZPT|"x"|1||1|20030224000001|"}&lt;BR /&gt;        $1 ~ /^490$/ {print $0"|"}'&lt;BR /&gt;&lt;BR /&gt;rgds, Robin</description>
      <pubDate>Wed, 26 Feb 2003 11:32:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-variables/m-p/2912671#M107685</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2003-02-26T11:32:32Z</dc:date>
    </item>
  </channel>
</rss>

