<?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: EOF within awk? in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998922#M98028</link>
    <description>Thanks,&lt;BR /&gt;the BEGIN &amp;amp; END were what I needed - the proper format and syntax was what I was lacking...your example answered my question&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 22 Aug 2006 12:14:58 GMT</pubDate>
    <dc:creator>Tim Howell</dc:creator>
    <dc:date>2006-08-22T12:14:58Z</dc:date>
    <item>
      <title>EOF within awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998919#M98025</link>
      <description>If the following was invoked...&lt;BR /&gt;awk -f script.awk `ls -t /tmp/logdir/log.*`&lt;BR /&gt;&lt;BR /&gt;Is there a way within script.awk to know when you have reached the end of an individual file? (or know when all files have been processed?) script.awk matches patterns and processes an indeterminant number of records in each file. I want to totalize the value of these records.&lt;BR /&gt;TIA&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Aug 2006 11:36:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998919#M98025</guid>
      <dc:creator>Tim Howell</dc:creator>
      <dc:date>2006-08-22T11:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: EOF within awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998920#M98026</link>
      <description>Shalom,&lt;BR /&gt;&lt;BR /&gt;how about inbedding awk in a read loop&lt;BR /&gt;&lt;BR /&gt;while not EOF&lt;BR /&gt;do&lt;BR /&gt; nice awk stuff&lt;BR /&gt;done &amp;lt; filename&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Tue, 22 Aug 2006 11:41:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998920#M98026</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2006-08-22T11:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: EOF within awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998921#M98027</link>
      <description>Yes awk has BEGIN and END blocks. When the normal block is finished (or if an explicit exit is done) the END block is executed.&lt;BR /&gt;This example should total the sizes of the files using an ls -l:&lt;BR /&gt;&lt;BR /&gt;my.awk&lt;BR /&gt;-------------------------&lt;BR /&gt;BEGIN {&lt;BR /&gt;  tot = 0&lt;BR /&gt;}&lt;BR /&gt;{&lt;BR /&gt;  tot += ($5 + 0)&lt;BR /&gt;}&lt;BR /&gt;END {&lt;BR /&gt;  print "Total: ",tot&lt;BR /&gt;}&lt;BR /&gt;--------------------------------------&lt;BR /&gt;&lt;BR /&gt;Invoke like this:&lt;BR /&gt;ls -l | awk -f my.awk&lt;BR /&gt;&lt;BR /&gt;Note the ($5 + 0). That is intential as it forces the 5th field (the file length in ls -l) into a numeric context. The standard idiom to force a field to string context is to append a null string.&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Aug 2006 11:45:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998921#M98027</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-08-22T11:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: EOF within awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998922#M98028</link>
      <description>Thanks,&lt;BR /&gt;the BEGIN &amp;amp; END were what I needed - the proper format and syntax was what I was lacking...your example answered my question&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Aug 2006 12:14:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998922#M98028</guid>
      <dc:creator>Tim Howell</dc:creator>
      <dc:date>2006-08-22T12:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: EOF within awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998923#M98029</link>
      <description>The END block is executed when the last record in the last file is processed apparently, and that's what I needed.</description>
      <pubDate>Tue, 22 Aug 2006 12:16:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998923#M98029</guid>
      <dc:creator>Tim Howell</dc:creator>
      <dc:date>2006-08-22T12:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: EOF within awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998924#M98030</link>
      <description>Note that the BEGIN block is not strictly needed as the variables are initialized as null strings -- which would evaluate in numeric context as zero but I don't never trust nobody for nothing so I always initialize values like "tot" in this example.</description>
      <pubDate>Tue, 22 Aug 2006 12:18:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998924#M98030</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-08-22T12:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: EOF within awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998925#M98031</link>
      <description>You can track individual files using FILENAME.  It will be updated line by line.  This example accumulates values in an array indexed by FILENAME.&lt;BR /&gt;&lt;BR /&gt;awk '{c[FILENAME]+=$2}END {for (f in c) {print f,c[f]}}' *</description>
      <pubDate>Tue, 22 Aug 2006 12:23:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998925#M98031</guid>
      <dc:creator>Mike Stroyan</dc:creator>
      <dc:date>2006-08-22T12:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: EOF within awk?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998926#M98032</link>
      <description>Hi Tim:&lt;BR /&gt;&lt;BR /&gt;How about(?):&lt;BR /&gt;&lt;BR /&gt;# cat .nbrlines&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    if (eof) {&lt;BR /&gt;        printf "%8d %s\n", $., $ARGV;&lt;BR /&gt;        close ARGV if eof;&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;...now:&lt;BR /&gt;&lt;BR /&gt;# ./nbrlines /etc/hosts /etc/services&lt;BR /&gt;      21 /etc/hosts&lt;BR /&gt;     187 /etc/services&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 22 Aug 2006 12:37:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/eof-within-awk/m-p/4998926#M98032</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-08-22T12:37:38Z</dc:date>
    </item>
  </channel>
</rss>

