Adding numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding numbers
# 1  
Old 10-07-2011
Adding numbers

Hi

I figured how to add my list of numbers. However how do I count so that after a certain number it lists the line.

Example:

Code:
12  test1
46  test2
195 test3
174 test4
634 test5
185 test6
94 test7

So basically add the numbers and when the addition reaches 300 or less
print the lines. So the outcome will be:

Code:
12 test1
46 test2
195 test3
174 test4

then ...

Code:
634 test5

then

Code:
185 test6
94 test7


Last edited by radoulov; 10-11-2011 at 09:44 AM.. Reason: Code tags!
# 2  
Old 10-07-2011
So the output should be the same as the input file? Please elaborate your question.
# 3  
Old 10-07-2011
I'm afraid that there is no parse-able question in your post.

"When the addition reaches 300 or less" ??

Could you post a follow up explaining what is being added and where the numbers are coming from?
# 4  
Old 10-07-2011
Hi

Sorry this is a bit confusing. What I am trying to do is add the Used bytes from the df -k output. However I want it separated in in chunks of 1000MB (1TB).
So basically take all the output and separate the filesystems in a total of 1TB.

Any easy way to do that?
# 5  
Old 10-07-2011
Depends on what your df -k input looks like. Not all systems are the same.

Show the input you get, and the output you want from it.
# 6  
Old 10-07-2011
Here you go ...Third field is the used
Code:
/vol/vol0/               140GB        4GB      136GB       3%  /vol/vol0/
/vol/nonprod00/          900GB      683GB      216GB      76%  /vol/nonprod00/
/vol/prod04/            7815GB     1935GB     5879GB      25%  /vol/prod04/
/vol/prod00/             180GB        3GB      176GB       2%  /vol/prod00/
/vol/nasp_archive/       400GB      201GB      198GB      50%  /vol/nasp_archive/
/vol/nasp_iface/         142GB       42GB       99GB      30%  /vol/nasp_iface/
/vol/nasp_bsi/             1GB        0GB        1GB       1%  /vol/nasp_bsi/
/vol/nasp_vertex/          1GB        0GB        1GB       1%  /vol/nasp_vertex/
/vol/nasp_sapmnt_mp2/        4GB        1GB        2GB      44%  /vol/nasp_sapmnt_mp2/
/vol/nasp_sapmnt_prd/       90GB       59GB       30GB      66%  /vol/nasp_sapmnt_prd/
/vol/nasp_sapmnt_srp/        6GB        1GB        4GB      26%  /vol/nasp_sapmnt_srp/
/vol/nasp_smd/             9GB        1GB        8GB      18%  /vol/nasp_smd/
/vol/nasp_ccms/            9GB        0GB        9GB       5%  /vol/nasp_ccms/
/vol/nasp_saptrans_erp/       67GB       44GB       22GB      66%  /vol/nasp_saptrans_erp/
/vol/nasp_saptrans_mip/        7GB        4GB        3GB      56%  /vol/nasp_saptrans_mip/
/vol/nasp_saptrans_ndp/       60GB       25GB       35GB      42%  /vol/nasp_saptrans_ndp/
/vol/nasp_saptrans_srm/       36GB        7GB       28GB      22%  /vol/nasp_saptrans_srm/
/vol/nasp_sapmnt_ndp/        4GB        2GB        2GB      48%  /vol/nasp_sapmnt_ndp/
/vol/sharedump/           99GB        0GB       98GB       0%  /vol/sharedump/
/vol/arcsight/           540GB      510GB       29GB      95%  /vol/arcsight/
/vol/sap_depot/          468GB      376GB       91GB      80%  /vol/sap_depot/
/vol/trp_sapmnt_sq1/        5GB        2GB        2GB      42%  /vol/trp_sapmnt_sq1/
/vol/trp_sapmnt_sq2/        5GB        2GB        2GB      43%  /vol/trp_sapmnt_sq2/
/vol/cnfo_prd/            29GB        0GB       29GB       1%  /vol/cnfo_prd/
/vol/ztrap/                0GB        0GB        0GB      81%  /vol/ztrap/
/vol/hpux_cnprd/          60GB       46GB       13GB      78%  /vol/hpux_cnprd/
/vol/cn_prd/              34GB       23GB       10GB      69%  /vol/cn_prd/

# 7  
Old 10-07-2011
Great, that's half of what I wanted.

Now the other half please -- what you want the processed output for that to look like.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding the squence numbers

Hi All, Could you please help me on this requirement. File data: A A A B B B i need the output like A1 A2 A3 B1 (3 Replies)
Discussion started by: bmk123
3 Replies

2. Shell Programming and Scripting

Adding (as in arithmetic) to numbers in columns in file, and writing new file with new numbers

Hi again. Sorry for all the questions — I've tried to do all this myself but I'm just not good enough yet, and the help I've received so far from bartus11 has been absolutely invaluable. Hopefully this will be the last bit of file manipulation I need to do. I have a file which is formatted as... (4 Replies)
Discussion started by: crunchgargoyle
4 Replies

3. UNIX for Dummies Questions & Answers

Adding Column Of Numbers

Hello. Trying to add a column of numbers and combine the 1st and 2nd fields as uniq with the new total. This works to add the numbers but can't figure an easy was to combine the 1st and 2nd column as the list is very long. awk '{s+=$3} END {print s}' bird dog 300 bird dog 100 cat clown 200... (1 Reply)
Discussion started by: jimmyf
1 Replies

4. Shell Programming and Scripting

help with adding up numbers

I have a file which has following contents which I want to add up. 28170.24 28170.24 28170.24 28170.24 28170.24 28170.24 28170.24 28170.24 28170.24 28170.24 28170.24 28170.24 28170.24 28170.24 139038.72 139038.72 139038.72 139038.72 (5 Replies)
Discussion started by: aksijain
5 Replies

5. Shell Programming and Scripting

Adding row of numbers

is there another way of doing the below: echo "7 3 8 2 2 1 3 83.4 8.2 4 8 73 90.5" | bc shell is bash. os is linux and sunos. bc seems to have an issue with long range of numbers (12 Replies)
Discussion started by: SkySmart
12 Replies

6. Shell Programming and Scripting

Adding numbers in a string

I am writing a bash script on ubuntu11.10 I have some string having numbers and letter and want to add all the numbers together For example 1s2d23f I want to perform 1 + 2 + 23 and store it in a variable (3 Replies)
Discussion started by: kristinu
3 Replies

7. UNIX for Dummies Questions & Answers

Adding numbers in unix

Hi this is quite a simple question... I am new to LINUX/UNIX and so I am just trying to create a very basic program. The idea is that when the user runs the program (from the shell) they enter 3 values and the program will add them up: "./sum 23 5 1 29" my code for this program is as follows: ... (4 Replies)
Discussion started by: csuieb
4 Replies

8. UNIX for Dummies Questions & Answers

adding hundreds of numbers

i know how to add two numbers using expr, but if i have a file with hundreds of numbers, how do i add them all together, without typing them all one by one? for example, file.txt contains 4 5 6 7 how can i give a command to add them, without typing $ expr `4 + 5 + 6 + 7` (7 Replies)
Discussion started by: FOBoy
7 Replies

9. Shell Programming and Scripting

adding a list of numbers 3 by 3

i have a list of numbers like this; 124 235 764 782 765 451 983 909 ... and i want to make a sum with the first 3 of them then the next 3 and so on. 124+235+764=1123 782+765+451=1998 ... some ideas? (4 Replies)
Discussion started by: Tártaro
4 Replies

10. Shell Programming and Scripting

Adding 2 numbers

I would like to write a script with BASH to add two numbers (integer) and write the result to the standard output. Please help! (7 Replies)
Discussion started by: Viper01
7 Replies
Login or Register to Ask a Question