Calculate Gigabyte and Terabyte


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculate Gigabyte and Terabyte
# 1  
Old 07-01-2008
Calculate Gigabyte and Terabyte

Guy's
I need help calculating a list of numbers that will be majority Terabytes but also have Gigabytes intermingled. So far when I calculate this, the Gigabytes throw off my true Terabyte total. Here is a list……

total 1.56 TB ,Mon Jun 09 23:59:11 2008
total 3.42 TB ,Tue Jun 10 23:59:10 2008
total 3.26 TB ,Wed Jun 11 23:59:11 2008
total 3.35 TB ,Thu Jun 12 23:59:12 2008
total 2.90 TB ,Fri Jun 13 23:59:09 2008
total 2.74 TB ,Sat Jun 14 23:59:10 2008
total 673.66 GB ,Sun Jun 15 23:59:08 2008
total 2.25 TB ,Mon Jun 16 23:59:10 2008
total 1.90 TB ,Tue Jun 17 23:59:09 2008
total 3.26 TB ,Wed Jun 18 23:59:11 2008
total 3.29 TB ,Thu Jun 19 23:59:11 2008
total 2.81 TB ,Fri Jun 20 23:59:09 2008
total 2.85 TB ,Sat Jun 21 23:59:11 2008
total 683.12 GB ,Sun Jun 22 23:59:07 2008
total 1.63 TB ,Mon Jun 23 23:59:10 2008
total 3.11 TB ,Tue Jun 24 23:59:11 2008
total 1.67 TB ,Wed Jun 25 23:59:12 2008
total 2.74 TB ,Thu Jun 26 23:59:07 2008
total 867.02 GB ,Fri Jun 27 23:59:07 2008


Thanks.
# 2  
Old 07-01-2008
If you want the sum:
Code:
awk 'END { printf "Total: %.2f TB\n", t }
{ t += $3 == "GB" ? $2 / 1024 : $2 }1' file

Use nawk or /usr/xpg4/bin/awk on Solaris.

Code:
$ nawk 'END { printf "Total: %.2f TB\n", t }
{ t += $3 == "GB" ? $2 / 1024 : $2 }1' file
total 1.56 TB ,Mon Jun 09 23:59:11 2008
total 3.42 TB ,Tue Jun 10 23:59:10 2008
total 3.26 TB ,Wed Jun 11 23:59:11 2008
total 3.35 TB ,Thu Jun 12 23:59:12 2008
total 2.90 TB ,Fri Jun 13 23:59:09 2008
total 2.74 TB ,Sat Jun 14 23:59:10 2008
total 673.66 GB ,Sun Jun 15 23:59:08 2008
total 2.25 TB ,Mon Jun 16 23:59:10 2008
total 1.90 TB ,Tue Jun 17 23:59:09 2008
total 3.26 TB ,Wed Jun 18 23:59:11 2008
total 3.29 TB ,Thu Jun 19 23:59:11 2008
total 2.81 TB ,Fri Jun 20 23:59:09 2008
total 2.85 TB ,Sat Jun 21 23:59:11 2008
total 683.12 GB ,Sun Jun 22 23:59:07 2008
total 1.63 TB ,Mon Jun 23 23:59:10 2008
total 3.11 TB ,Tue Jun 24 23:59:11 2008
total 1.67 TB ,Wed Jun 25 23:59:12 2008
total 2.74 TB ,Thu Jun 26 23:59:07 2008
total 867.02 GB ,Fri Jun 27 23:59:07 2008
Total: 44.91 TB

# 3  
Old 07-01-2008
How about just dividing your GB by 1000 to get TB and then add them up. You have the units (TB or GB) in each line. You only need to move the decimal over 3 places to the left....

813.5 GB = 0.8135 TB
25 GB = 0.025 TB
etc...
# 4  
Old 07-01-2008
Thank you so much Radoulov. You are an nawk genius.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Multi-terabyte filesystem space increase on AIX7.1

Hi, I need to increase a filesystem from around 1TB to 15TB on a running AIX7.1 TSM server. This will be by far the largest single filesystem increase I've ever performed, or even heard of. The volume group already has enough disk available (in fact the filesystem was always intended to be... (10 Replies)
Discussion started by: alanp36
10 Replies

2. Shell Programming and Scripting

Sum in terabyte

Hello, can someone help me in this I have a file of sizes in kilobyte I want to caculte the sum in terabyte using awk I would like to have one digit after the decimal point ( 2.8 TB for example) cat file 2881301319 3061567196 3010347398 3029693706 2906516319 2444536488... (2 Replies)
Discussion started by: Sara_84
2 Replies

3. Hardware

Intel vs Dlink NIC Gigabyte price point difference

Hi, I wondering about intel and dlink gigabyte desktop nic card price point, May i ask if someone know the difference between the two gigabyte nic card, I found at my local electronic store that theres a price difference between the two the intel is double the price of the dlink although the... (4 Replies)
Discussion started by: jao_madn
4 Replies

4. SCO

SCO UNIX OpenServer 5.0.7 on Gigabyte GA-X58A-OC Motherboard

Does anyone here have experience with running SCO UNIX OpenServer 5.0.7 on the Gigabyte GA-X58A-OC motherboard? Are there any problems? (2 Replies)
Discussion started by: Transpower
2 Replies

5. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

6. UNIX for Dummies Questions & Answers

How can partition out /var with these two separate 10 gigabyte disks?

In my company ,there is a mail server that services approximately 3,000 users. 2,000 users access their email via a POP-3 service, while the remaining 1,000 users access their email via a Unix mail reader. Recently users have complained about speed of disk access, so a new 10 gigabyte disk has... (1 Reply)
Discussion started by: lemon_06
1 Replies

7. Shell Programming and Scripting

How To Calculate

I have 2 variables in my shell scripts in which i am using awk and calculating 2 files and getting 2 different variable called in_total and out_total. I want to subtract one variable from another so plz tell me how i can do that. Example is: cat in_file | awk -F: '{ in_total += $1 * 86400... (3 Replies)
Discussion started by: krishna_sicsr
3 Replies

8. Shell Programming and Scripting

Unique values from a Terabyte File

Hi, I have been dealing with a files only a few gigs until now and was able to get out by using the sort utility. But now, I have a terabyte file which I want to filter out unique values from. I have a server having 8 processor and 16GB RAM with a 5 TB hdd. Is it worthwhile trying to use... (6 Replies)
Discussion started by: Legend986
6 Replies

9. UNIX for Advanced & Expert Users

How to install Linux on an external 320 gigabyte hard drive

Hi all, I would to know if I can install Linux on an external 320 gigabyte hard drive..I have Windows XP on my internal hard drive which is 80 GB , but this installation on 320 external HDD is for testing purpose If it is possible to install Linux on the external drive, will it cause any... (5 Replies)
Discussion started by: bsandeep_80
5 Replies
Login or Register to Ask a Question