<?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 print variable in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206638#M714256</link>
    <description>You must these variables to awk&lt;BR /&gt;&lt;BR /&gt;awk -v var1=$setdate -v var2=$setime '{&lt;BR /&gt;print $1","var1","var2 ...&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc</description>
    <pubDate>Tue, 02 Mar 2004 07:28:16 GMT</pubDate>
    <dc:creator>Jean-Luc Oudart</dc:creator>
    <dc:date>2004-03-02T07:28:16Z</dc:date>
    <item>
      <title>awk print variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206636#M714254</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I need to something like the following:&lt;BR /&gt;&lt;BR /&gt;2 variables eg&lt;BR /&gt;&lt;BR /&gt;sedate=20040302&lt;BR /&gt;setime=130000&lt;BR /&gt;&lt;BR /&gt;echo a string to create a new one:&lt;BR /&gt;&lt;BR /&gt;echo "29Feb 14:21:15, ,XXXXXXXX,FOS00001980,P63566,0293/108458,1/9,Not extracted" |awk -F, '{print $1","$sedate $setime","$3","$4","$5","$6","$7}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;However I have not got the handling of the variables right, as I get :&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;awk: Field $() is not correct.&lt;BR /&gt; The input line number is 1.&lt;BR /&gt; The source line number is 1.&lt;BR /&gt;&lt;BR /&gt;Any help apreciated!&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Mar 2004 07:20:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206636#M714254</guid>
      <dc:creator>Patrick Stevens</dc:creator>
      <dc:date>2004-03-02T07:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: awk print variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206637#M714255</link>
      <description>try&lt;BR /&gt;&lt;BR /&gt;printf "%s,%s %s,%s,%s,%s,%s,%s",$1,$sedate,$setime,$3,$4,$5,$6,$7&lt;BR /&gt; &lt;BR /&gt;INstead of your "print" statement</description>
      <pubDate>Tue, 02 Mar 2004 07:26:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206637#M714255</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-03-02T07:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: awk print variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206638#M714256</link>
      <description>You must these variables to awk&lt;BR /&gt;&lt;BR /&gt;awk -v var1=$setdate -v var2=$setime '{&lt;BR /&gt;print $1","var1","var2 ...&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Tue, 02 Mar 2004 07:28:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206638#M714256</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-03-02T07:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: awk print variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206639#M714257</link>
      <description>&lt;BR /&gt;You need to get those variables into awk. Jean-Luc shows a good solution to that using command line arguments.&lt;BR /&gt;An alternative is to use the ENVIRON array that awk provides. Something like (untested):&lt;BR /&gt;awk -F, 'print $1,ENVIRON["sedate"] ENVIRON["setime"],$3 ....&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Mar 2004 09:57:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206639#M714257</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-03-02T09:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: awk print variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206640#M714258</link>
      <description>the above poster have shown you how to get the variables into awk.  &lt;BR /&gt;&lt;BR /&gt;here are a couple of ways without using awk&lt;BR /&gt;using sed. be sure to use double quotes&lt;BR /&gt;&lt;BR /&gt;print "29Feb 14:21:15, ,XXXXXXXX,FOS00001980" | sed "s/\(.*\),,/\1,$sedate $setime,/"&lt;BR /&gt;&lt;BR /&gt;and just using the shell&lt;BR /&gt;&lt;BR /&gt;string="29Feb 14:21:15, ,XXXXXXXX,FOS00001980"&lt;BR /&gt;last=${string#*,}&lt;BR /&gt;first=${string%%,*}&lt;BR /&gt;printf "%s,%s %s%s\n" $first $sedate setime $last</description>
      <pubDate>Tue, 02 Mar 2004 11:39:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206640#M714258</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-03-02T11:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: awk print variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206641#M714259</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;SETDATE=20040302&lt;BR /&gt;SETTIME=140000&lt;BR /&gt;echo "29Feb 14:21:15,,XXXXXXXX,FOS00001980,P63566,0293/108458,1/9,Not extracted" |awk '{print $1","SEDATE" "SETIME" ,"$3","$4","$5","$6","$7}' SEDATE=${SETDATE} SETTIME=${SETTIME}&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;echo "29Feb 14:21:15,,XXXXXXXX,FOS00001980,P63566,0293/108458,1/9,Not extracted" |awk '{print $1","SEDATE" "SETIME" ,"$3","$4","$5","$6","$7}' SEDATE=20040302 SETTIME=140000&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Rory&lt;BR /&gt;(I tested #2 not #1 but both should work)&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Mar 2004 14:11:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206641#M714259</guid>
      <dc:creator>Rory R Hammond</dc:creator>
      <dc:date>2004-03-03T14:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: awk print variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206642#M714260</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Why don't you just echo also the  variables into the pipeline ? Something like:&lt;BR /&gt;&lt;BR /&gt;sedate=20040302&lt;BR /&gt;setime=130000&lt;BR /&gt;&lt;BR /&gt;echo a string to create a new one:&lt;BR /&gt;&lt;BR /&gt;echo "29Feb 14:21:15,$setdate,$setime,XXXXXXXX,FOS00001980,P63566,0293/108458,1/9,Not extracted" |awk -F, '{print $1","$2","$3","$4","$5","$6","$7","$8}'&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Mar 2004 16:02:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206642#M714260</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2004-03-03T16:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: awk print variable</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206643#M714261</link>
      <description>Another way to do this would be:&lt;BR /&gt;&lt;BR /&gt;echo "SEDATE",$sedate &amp;gt; myfile&lt;BR /&gt;echo "SETIME",$setime &amp;gt;&amp;gt; myfile&lt;BR /&gt;echo "29Feb 14:21:15, ,XXXXXXXX,FOS00001980,P63566,0293/108458,1/9,Not extracted" &amp;gt;&amp;gt; myfile&lt;BR /&gt;&lt;BR /&gt;NOTE you could actually echo multiple of these last lines and have things work if you had a constant SEDATE and SETIME that you wanted to use and multiple "data" lines.&lt;BR /&gt;&lt;BR /&gt;Then create an awk file called se.awk&lt;BR /&gt;/^SEDATE/ {sedate=$2;next;}&lt;BR /&gt;/^SETIME/ {setime=$2;next;}&lt;BR /&gt;{print $1","sedate setime","$3","$4","$5","$6","$7}&lt;BR /&gt;&lt;BR /&gt;Then run:&lt;BR /&gt;awk -f se.awk myfile &amp;gt; myoutputfile&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Kent M. Ostby&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Mar 2004 18:28:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-print-variable/m-p/3206643#M714261</guid>
      <dc:creator>Kent Ostby</dc:creator>
      <dc:date>2004-03-03T18:28:00Z</dc:date>
    </item>
  </channel>
</rss>

