Operating System - HP-UX
1831552 Members
3523 Online
110025 Solutions
New Discussion

Re: Problem in counting total no of bytes

 
SOLVED
Go to solution
diwa
Frequent Advisor

Problem in counting total no of bytes

Hi,

I am using one awk cmd which counts no of bytes and then calculate no of MB out of that.

I have put this cmd in sh file:

Here i am counting the number of bytes.

ls -lrt *vix |awk '{sum+=$5} END { printf("%10d \n",sum)}'

Problem: When i am giving ls -lrt it is out putting total no of bytes "2147483647".

When i am giving

ls -lrt |awk '{sum+=$5} END { printf("%10d \n",sum)}'
It is giving same out put "2147483647".

I am wondering that how it is happening because dir is having .DAT,.vix, any other types of files.

Till now i was confident that this calculating right but i got shocked it is not.


Can some please suggest soemthing what is wrong? Also files are very hugh in size like 1103309312 that much size.

Thanks
4 REPLIES 4
AwadheshPandey
Honored Contributor

Re: Problem in counting total no of bytes

awk 'BEGIN{sum=0}{sum+=$5/1024/1024}END {print sum}'
It's kind of fun to do the impossible
Steven Schweda
Honored Contributor
Solution

Re: Problem in counting total no of bytes

> [...] "2147483647".

Looks just like the biggest possible signed
32-bit integer, doesn't it? You might try
floating point:

[...] printf("%.15g \n",sum) [...]
diwa
Frequent Advisor

Re: Problem in counting total no of bytes

Hi Steven,

Thanks a ton,

Now it is working fine.

diwa
Frequent Advisor

Re: Problem in counting total no of bytes

Hi,

I got complete solution of my problem.


Thanks