Operating System - HP-UX
1827343 Members
5733 Online
109963 Solutions
New Discussion

Re: Adding totals in a file

 
SOLVED
Go to solution
steven Burgess_2
Honored Contributor

Adding totals in a file

Hi all

I've got an issue with a disk array - I have attempted to backthe data up in vg02 from the array. fbackup appeared to hang, i killed the processes, checked the tape index and appear to have a whole load of data on the tape - how much is the question. The usage of vg02 is 3.5 gig - if I grep a file from the index i can see the file and it's size. I have printed column 1 from the index ( file sizes ) and output to another file.

How can I add the total of all the lines in the file to get a calculation of how much data if have managed to back up, ie

12345
12345
12345

= 37035

Regards

Steve
take your time and think things through
5 REPLIES 5
harry d brown jr
Honored Contributor
Solution

Re: Adding totals in a file

Steven,

use awk

awk 'BEGIN {total=0;} {total=total+$1;} END {print total,"\n";}'

live free or die
harry
Live Free or Die
steven Burgess_2
Honored Contributor

Re: Adding totals in a file

Hi Harry

As in

cat file | awk 'BEGIN {total=0;} {total=total+$1;} END {print total,"\n";}'

This gives

3.83543e+09

Excuse me if the above is correct - could you explain the output

Thanks

Steve


take your time and think things through
James R. Ferguson
Acclaimed Contributor

Re: Adding totals in a file

Hi Steven:

The sum is in scientific notation. Hence, "e+09" means multiply by 10^9 ( or shift the decimal place 9-times to the right). In your example:

3.83543e+09 = 3,835,430,000

Regards!

...JRF...


steven Burgess_2
Honored Contributor

Re: Adding totals in a file

Hi

Thanks guys

Looks like I have all the data on the tape

Regards

Steve
take your time and think things through
Bill Hassell
Honored Contributor

Re: Adding totals in a file

Actually, you can test this a lot quicker. The table of contents is written *before* the files are written. Therefore, the last file in the index is the last file on tape. By restoring the last file on the tape, you'll know whether the previous tape is valid.

Use this:

cd /var/tmp

frecover -I /var/tmp/fbfiles -f /dev/rmt/
tail /var/tmp/fbfiles(find the last file on the backup)

frecover -xmF -f /dev/rmt/ -i /whatever_the_last_file_is

If it restores OK, then all the previous files are likely OK.


Bill Hassell, sysadmin