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.

If you want the sum:

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.

$ 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

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...

Thank you so much Radoulov. You are an nawk genius.:b: