<?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 and prinf in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-prinf/m-p/4623738#M675945</link>
    <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Another way is to use Perl and do something like:&lt;BR /&gt;&lt;BR /&gt;# echo "abc def ghi jkl xxx yyy zzz"|perl -nae '{printf "# %-7s %9s %16s %s\n",@F[1..3],"@F[4..@F]"}'&lt;BR /&gt;&lt;BR /&gt;Perl counts zero-relative whereas 'awk' counts from one.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Mon, 26 Apr 2010 11:20:25 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2010-04-26T11:20:25Z</dc:date>
    <item>
      <title>awk and prinf</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-prinf/m-p/4623736#M675943</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;I am replacing the 4th feild of an input line and then formatting the input line using printf&lt;BR /&gt;&lt;BR /&gt;Here is my code:&lt;BR /&gt;Line="# IN01379     Larry      2010/03/17    (should be the same as FIW-LR AM)"&lt;BR /&gt; REPL_DT=`date +'%Y\/%m\/%d'`&lt;BR /&gt; REP_LINE=$(echo $Line | awk -v var=$REPL_DT '{$4=var; print}')&lt;BR /&gt; NEW_LINE=$(echo $REP_LINE |  awk '{printf "# %-7s %9s %16s\n", $2,$3,$4}')&lt;BR /&gt;&lt;BR /&gt;The problem here is, since I am formatting only till $4 in prinf statement, anything that comes after the 4 feild is not printed.  The number of feilds/words that comes after 4th feild is not fixed.&lt;BR /&gt;&lt;BR /&gt;I do not have to format the feilds after $4. But I have to format the first four feilds as shown above. &lt;BR /&gt;&lt;BR /&gt;Any way to format only the first 4 feilds of the input line and retain the rest of line.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Apr 2010 08:16:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-prinf/m-p/4623736#M675943</guid>
      <dc:creator>gsudha</dc:creator>
      <dc:date>2010-04-26T08:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: awk and printf</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-prinf/m-p/4623737#M675944</link>
      <description>&lt;!-- !*# --&gt;&lt;P&gt;&amp;gt;Anyway to format only the first 4 fields of the input line and retain the rest of line&lt;BR /&gt;&lt;BR /&gt;You could use a for-loop to print the rest of the fields:&lt;BR /&gt;for (i=5; i &amp;lt;=NF; ++i)&lt;BR /&gt;printf " %s", $I&lt;BR /&gt;print ""&lt;/P&gt;</description>
      <pubDate>Sun, 21 Aug 2011 22:32:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-prinf/m-p/4623737#M675944</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-08-21T22:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: awk and prinf</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-prinf/m-p/4623738#M675945</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Another way is to use Perl and do something like:&lt;BR /&gt;&lt;BR /&gt;# echo "abc def ghi jkl xxx yyy zzz"|perl -nae '{printf "# %-7s %9s %16s %s\n",@F[1..3],"@F[4..@F]"}'&lt;BR /&gt;&lt;BR /&gt;Perl counts zero-relative whereas 'awk' counts from one.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 26 Apr 2010 11:20:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-prinf/m-p/4623738#M675945</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-04-26T11:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: awk and prinf</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-prinf/m-p/4623739#M675946</link>
      <description>Thank you very much.  Your solution using perl works.  The below code, using awk with substr and index also works:&lt;BR /&gt;&lt;BR /&gt;echo "hi hello how are you doing" | awk '{printf "# %-7s %9s %16s %s\n", $2,$3,$4,substr($0,index($0,$5))}'</description>
      <pubDate>Tue, 27 Apr 2010 03:16:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-and-prinf/m-p/4623739#M675946</guid>
      <dc:creator>gsudha</dc:creator>
      <dc:date>2010-04-27T03:16:57Z</dc:date>
    </item>
  </channel>
</rss>

