<?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 problem - addition? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129258#M688218</link>
    <description>Hi Thanks a lot. That's really good. But I'm just curious, what's wrong with this?&lt;BR /&gt;&lt;BR /&gt;ls -l | awk '{sum += $5};END{printf "%d\n", sum"&lt;BR /&gt;&lt;BR /&gt;It prints out the same result?? no? And then why did you skip the "Total" word.. how would awk "add" a word ?? I thought it would just skip it?&lt;BR /&gt;&lt;BR /&gt;But you're in inspiration, and I'm giving u 8 points, and the nice lady above 2 points. &lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 11 Sep 2008 12:09:48 GMT</pubDate>
    <dc:creator>Vassilios</dc:creator>
    <dc:date>2008-09-11T12:09:48Z</dc:date>
    <item>
      <title>Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129252#M688212</link>
      <description>Hello,&lt;BR /&gt;Would someone here know how to use awk to do an addition?&lt;BR /&gt;&lt;BR /&gt;Here's what I'm trying to do:&lt;BR /&gt;&lt;BR /&gt;if you do an ls -l, it prints out direcctory/file sizes. Right? So, let's say the column in which the directory falls is the 9th? I forget.. but its around the 9th,&lt;BR /&gt;&lt;BR /&gt;so, I now want to add the TOTAL file sizes/sub directory sizes in a directory, that may contain 200 files or sub folders. &lt;BR /&gt;&lt;BR /&gt;ls -l | swk '{print $9}' | &lt;WHAT goes="" here="" to="" add="" all="" this="" up=""&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;/WHAT&gt;</description>
      <pubDate>Thu, 11 Sep 2008 11:32:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129252#M688212</guid>
      <dc:creator>Vassilios</dc:creator>
      <dc:date>2008-09-11T11:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129253#M688213</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Instead you can choose easier way !!&lt;BR /&gt;&lt;BR /&gt;Use du -sk to take out size of directory including all sub dirs and files in it&lt;BR /&gt;&lt;BR /&gt;#du -sk /tmp/dir&lt;BR /&gt;size in KB&lt;BR /&gt;&lt;BR /&gt;MB=KB/1000</description>
      <pubDate>Thu, 11 Sep 2008 11:38:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129253#M688213</guid>
      <dc:creator>Deepak Kr</dc:creator>
      <dc:date>2008-09-11T11:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129254#M688214</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;# ls -l | awk '/^total/ {next};{SUM+=$5};END{printf "%10d\n",SUM}'&lt;BR /&gt;&lt;BR /&gt;...note that this skips the "total" line returned by 'ls -l'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Sep 2008 11:40:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129254#M688214</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-09-11T11:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129255#M688215</link>
      <description>You may want to include a grep after the ls command to capture only the files and exclude directories soft links and other special files. Such as &lt;BR /&gt;ls -l |grep ^- | awk...&lt;BR /&gt;Note that in the "ls -l" listing for a subdirectory line the size number does NOT represent the contents of the subdirectory but rather its file table. You may or may not want to exclude these. If you want to sum up the contents of subrirectories you have to use the df commnad as noted above.</description>
      <pubDate>Thu, 11 Sep 2008 11:53:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129255#M688215</guid>
      <dc:creator>TTr</dc:creator>
      <dc:date>2008-09-11T11:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129256#M688216</link>
      <description>Also:&lt;BR /&gt;&lt;BR /&gt;To find&lt;BR /&gt;a) The total number of files in a directory&lt;BR /&gt;b) The total filesize&lt;BR /&gt;&lt;BR /&gt;#cd /dir&lt;BR /&gt;#ls -l | awk '$6{b+=$5;a+=1}END{print a,b}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Sep 2008 12:02:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129256#M688216</guid>
      <dc:creator>Deepak Kr</dc:creator>
      <dc:date>2008-09-11T12:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129257#M688217</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;I agree with TTr insofar as you probably want to exclude the space used for directories and for symbolic links.  You don't need to add another process, namely 'grep', though since 'awk' easily does this too:&lt;BR /&gt;&lt;BR /&gt;# ls -l | awk '!/^-/ {next};{SUM+=$5};END{printf "%10d\n",SUM}'&lt;BR /&gt;&lt;BR /&gt;Now, if you truly want the size of all *files* in all of the subdirectories in your 'ls' path, you can add the '-R' switch to 'ls' to do:&lt;BR /&gt;&lt;BR /&gt;# ls -lR | awk '!/^-/ {next};{SUM+=$5};END{printf "%10d\n",SUM}'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Sep 2008 12:08:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129257#M688217</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-09-11T12:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129258#M688218</link>
      <description>Hi Thanks a lot. That's really good. But I'm just curious, what's wrong with this?&lt;BR /&gt;&lt;BR /&gt;ls -l | awk '{sum += $5};END{printf "%d\n", sum"&lt;BR /&gt;&lt;BR /&gt;It prints out the same result?? no? And then why did you skip the "Total" word.. how would awk "add" a word ?? I thought it would just skip it?&lt;BR /&gt;&lt;BR /&gt;But you're in inspiration, and I'm giving u 8 points, and the nice lady above 2 points. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Sep 2008 12:09:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129258#M688218</guid>
      <dc:creator>Vassilios</dc:creator>
      <dc:date>2008-09-11T12:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129259#M688219</link>
      <description>I'm just curious about one thing. In a directory where there are long listings (i.e. 100's of files), whether I use my way, or your way, the figures change. &lt;BR /&gt;&lt;BR /&gt;It doesn't seem to be stable when adding...&lt;BR /&gt;&lt;BR /&gt;Why is that??&lt;BR /&gt;&lt;BR /&gt;Try it out.. &lt;BR /&gt;&lt;BR /&gt;Here's my way:&lt;BR /&gt;&lt;BR /&gt;ls -l | awk '{SUM += $5};END{printf "%d\n", SUM}'&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Sep 2008 12:18:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129259#M688219</guid>
      <dc:creator>Vassilios</dc:creator>
      <dc:date>2008-09-11T12:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129260#M688220</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; But I'm just curious, what's wrong with this?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; ls -l | awk '{sum += $5};END{printf "%d\n", sum"&lt;BR /&gt;&lt;BR /&gt;&amp;gt; It prints out the same result?? no? And then why did you skip the "Total" word.. how would awk "add" a word ?? I thought it would just skip it?&lt;BR /&gt;&lt;BR /&gt;The answer is that there is no fifth (5th) column for the "total" heading line, so 'awk' adds zero as it were.  I chose to explicitly skip the "total" line simply to be pure and rigorous.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I'm just curious about one thing. In a directory where there are long listings (i.e. 100's of files), whether I use my way, or your way, the figures change. &lt;BR /&gt;&lt;BR /&gt;I suspect that you have entries special files (character and block devices).  Sockets have a size of zero so those wouldn't matter.  My second suggestion confined the totals to only *regular* files --- not directories nor special files nor symbolic links.&lt;BR /&gt;&lt;BR /&gt;If we want to be pedantic we should probably account for hard-linked files too :-))&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF... &lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Thu, 11 Sep 2008 12:26:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129260#M688220</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-09-11T12:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129261#M688221</link>
      <description>thanks everyone. You were all brilliant. To whom do I owe the points?</description>
      <pubDate>Thu, 11 Sep 2008 12:45:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129261#M688221</guid>
      <dc:creator>Vassilios</dc:creator>
      <dc:date>2008-09-11T12:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129262#M688222</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; thanks everyone. You were all brilliant. To whom do I owe the points?&lt;BR /&gt;&lt;BR /&gt;Points can be awarded to everyone as you see fit.  There is no limit to the overall number that can be assigned.  Please read :&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums12.itrc.hp.com/service/forums/helptips.do?#34" target="_blank"&gt;http://forums12.itrc.hp.com/service/forums/helptips.do?#34&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Sep 2008 12:50:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129262#M688222</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-09-11T12:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Awk problem - addition?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129263#M688223</link>
      <description>The awk program is using 32-bit arithmetic so the suming in awk overflows at 2147483647. (2^31 - 1). It does not error out, it keeps adding but the sum does not change once you reach the above number. At least it did it on my 11.11 workstation. I did not check if there are any patches for awk.&lt;BR /&gt;&lt;BR /&gt;An alternative to adding with awk would be to use bc or dc. I did it using a "while read" loop, I don't know how to do it with inline bc commands. Maybe a bc expert can offer a quicker solution.&lt;BR /&gt;&lt;BR /&gt;I also added a comment to your other posting about "ps -ef | awk"</description>
      <pubDate>Thu, 11 Sep 2008 21:12:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-addition/m-p/5129263#M688223</guid>
      <dc:creator>TTr</dc:creator>
      <dc:date>2008-09-11T21:12:06Z</dc:date>
    </item>
  </channel>
</rss>

