Visit Our UNIX and Linux User Community


File Size calculation with AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Size calculation with AWK
# 1  
Old 09-04-2009
File Size calculation with AWK

Hello Friends,

Im calculating file sizes with below AWK script. I do this before some spesific files are transferred. I run the script it works but after several running it stuck with a limit of 2147483647 (2 Gbytes -1 byte) and cant exceed this. Something is wrong and I can't proceed, would appreciate any help.

Code:
find . \( -name "*.gz" -o -name "*.tar" -o -name "*.rar" \) -mtime +1 -exec ls -l {} \;| awk '/^-/ {a[$6 OFS sprintf("%2d",$7)]+=$5} END {for(i in a) printf "%s %15d %6s\n",i,a[i],"Bytes"}' >> sum_of_files.txt

SUM=`awk '{a+=$3}END{printf "%15d\n",a}'  sum_of_files.txt`

i find .gz, .tar or .rar files which are older than 1 day under a main directory and execute "ls -l" and calculate sizes but i also print 6th and 7th columns too into same file just for info.Then using 3rd colums i calculate the all sizes as a total sum.

Code:
sum_of_files.txt
Sep  4       416192512  Bytes
Sep  4       416192512  Bytes
Sep  4       416192512  Bytes
Sep  4       416192512  Bytes
Sep  4       416192512  Bytes
Sep  4       416192512  Bytes
Sep  4       416192512  Bytes
Sep  4       416192512  Bytes

The output of script is like below (sum of bytes above file) :
Code:
server{root}>./size.sh 
      416192512  # this is size of compressed folder only it is calculated #
server{root}>./size.sh 
      832385024
server{root}>./size.sh 
     1248577536
server{root}>./size.sh 
     1664770048
server{root}>./size.sh 
     2080962560
server{root}>./size.sh 
     2147483647
server{root}>./size.sh 
     2147483647
server{root}>./size.sh 
     2147483647



---------- Post updated at 05:12 PM ---------- Previous update was at 03:41 PM ----------

I'm afraid my system does not support 64 bits of aritmethic operations

Code:
 root@SL02 # file  `which bc` `which awk` `which perl`
/usr/bin/bc:    ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
/usr/bin/awk:   ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
/usr/bin/perl:  ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped

Please advise, is my system unsufficient for such aritmethic operations and should i upgrade the solaris version to 64-Bit exec SPARC?

thanks by advanced
# 2  
Old 09-04-2009
I cannot tell what is going on BUT - awk uses double precision arithmetic. It supports number up to 10^308 on your system:
Code:
> file `which awk`
/usr/xpg4/bin/awk:      ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
> echo "12345678910 12345678910" | awk '{sum=$1; sum+=$2; print sum}'
24691357820
> echo "12345678910 12345678910" | nawk '{sum=$1; sum+=$2; print sum}'
24691357820


Previous Thread | Next Thread
Test Your Knowledge in Computers #184
Difficulty: Easy
Less than 4% of those surveyed at UNIX.com indicated that csh was their most useful shell.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk percentage calculation from a file

i have a file say test with the below mentioned details Folder Name Total space Space used /test/test1 500.1GB 112.0 GB /test/test2 3.2 TB 5TB /test/test3 3TB 100GB i need to calculate percentage of each row based on total space and space used and copy... (9 Replies)
Discussion started by: venkitesh
9 Replies

2. Shell Programming and Scripting

awk calculation with zero as N/A

In the below awk, I am trying to calculate percent for a given id. It is very close the problem is when the # being used in the calculation is zero. I am not sure how to code this condition into the awk as it happens frequently. The portion in italics was an attempt but that lead to an error. Thank... (13 Replies)
Discussion started by: cmccabe
13 Replies

3. Shell Programming and Scripting

awk split and awk calculation in the same command

I am trying to run the awk below. My question is when I split the input, then run anotherawk to perform a calculation using that splitas the input there are no issues. When I try to combine them the output is not correct, is the split not working or did I do it wrong? Thank you :). input ... (8 Replies)
Discussion started by: cmccabe
8 Replies

4. Shell Programming and Scripting

Size calculation MB to GB

pcmpath query device |awk 'BEGIN{print "TYPE\tDEVICE NAME\tSERIAL\tSIZE\tHOSTNAME"} /DEVICE/ { disk=$5 printf "%s\t", $7 printf "%s\t", disk getline; printf "%s\t", substr($2, length($2)-3) ("bootinfo -s " disk) | getline; printf... (3 Replies)
Discussion started by: Daniel Gate
3 Replies

5. Programming

arithmetic calculation using awk

hi there again, i need to do a simple division with my data with a number of rows. i think i wanted to have a simple output like this one: col1 col2 col3 val1 val2 val1/val2 valn valm valn/valm any suggestion is very much appreciated. thanks much. (2 Replies)
Discussion started by: ida1215
2 Replies

6. Shell Programming and Scripting

awk file size limit

My code is awk '{ out=split(FILENAME,a,"/") sub(/\./,"_",a) sub(/\-/,"_",a) NEWSTRING="main_"a"_"a"(" # The word we want to insert gsub(/main\(/,NEWSTRING); # the word to be replaced print "Main becomes ",NEWSTRING")","in file ",FILENAME >> "/home/ds2/test/NEW2.txt" ... (4 Replies)
Discussion started by: senior_ahmed
4 Replies

7. Shell Programming and Scripting

awk calculation problem

I have a list of coordinate data, sampled below. 54555209 784672723 I want it as: 545552.09 7846727.23 Below is my script: BEGIN {FS= " "; OFS= ","} {print $1*.01,$2*.01} This is my outcome: 5.5e7 7.8e8 How do I tell awk that I want to keep all the digits instead of outputting... (1 Reply)
Discussion started by: ndnkyd
1 Replies

8. Shell Programming and Scripting

Partitioning script for rescue mode (disk size calculation)

Hello! I need to write partitioning script wich would work in rescue mode. It will prepare partitions and unpack linux on it. However I need to calculate whole size of the disk and create: /dev/sda1 --> One big partition (minus (2*size of memory) for swap) /dev/sda2 --> Swap partition... (1 Reply)
Discussion started by: pug123
1 Replies

9. Shell Programming and Scripting

awk calculation

Hallo all, I have a script which creates an output ... see below: root@a7germ:/tmp/pax > cat 20061117.txt 523.047 521.273 521.034 517.367 516.553 517.793 513.114 513.940 I would like to use awk to calculate the (a)total sum of the numbers (b) The average of the numbers. Please... (4 Replies)
Discussion started by: kekanap
4 Replies

10. Shell Programming and Scripting

Awk an file size

I have been using x=ls -la "$f" | awk '{print $5}' This allows me to the size of all the files in $f and echo $x later . The only problem is instead of protecting the file size format of ls -la which is right to left, it rearranges it and reads it left to right. Cyborg was kind... (1 Reply)
Discussion started by: chrchcol
1 Replies

Featured Tech Videos