Summation of the column value in an interval.


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Summation of the column value in an interval.
# 1  
Old 05-18-2009
Summation of the column value in an interval.

Hey,

I have a file with following data..
and I want to get the summation of 10th column. And this happens in every 10 seconds for a minute max.

242001 A mqsitst 794864 1249516 0 60 20 293050400 77016 * 02:05:33 - 0:04 DataFlowEngine EAITIBR2_BROKER 384403e1-1001-0000-0080-cc759314a02e IDS_CCASS 0
242001 A mqsitst 978998 1249516 0 60 20 24284a400 56092 * 02:05:33 - 0:03 DataFlowEngine EAITIBR2_BROKER 9fa202e1-1001-0000-0080-cc759314a02e 21CD1 0
242001 A mqsitst 1040482 1134684 0 60 20 13d86400 78684 * 02:05:35 - 0:04 DataFlowEngine EAIDQBR2_BROKER 6f8aa7d6-1001-0000-0080-be57c7f1134d WAMS1 0

The BOLD faced has to be added and its in the 10th column.

What should i do to make it easily done ?

Thanks
# 2  
Old 05-18-2009
this will add up the 10th column i didn't understand for what you mentioned "And this happens in every 10 seconds for a minute max"
Code:
awk '{sum += $10}END{print sum}' filename

# 3  
Old 05-18-2009
Quote:
Originally Posted by vidyadhar85
this will add up the 10th column i didn't understand for what you mentioned "And this happens in every 10 seconds for a minute max"
Code:
awk '{sum += $10}END{print sum}' filename

I mean to say by that, that the script/command will execute for a minute and sleep would be of 10 seconds. (I minute = 60 seconds ; i.e. 6 times script will run)
In that timespan, i would like to keep the 6 summations togather and then would add them finally.

Smilie
# 4  
Old 05-18-2009
in that case you have to save the summation into some intermediate file and add them up at the end of min
# 5  
Old 05-18-2009
Re

Quote:
Originally Posted by vidyadhar85
in that case you have to save the summation into some intermediate file and add them up at the end of min
Yes..I did that.
Its fine and working.

ThanksSmilie
# 6  
Old 05-18-2009
Quote:
Originally Posted by vidyadhar85
in that case you have to save the summation into some intermediate file and add them up at the end of min
By the way...following is the script. Its running while TRUE and sleep is 10 seconds. It'll work but is Cntrl+C interrupt only solution to stop it? OR can I run while loop for just 1 minute.

while true
do
# echo "********To stop it, press the Interrupt key sequence. Cntrl+C **********"
ps -elf | grep DataFlow > InputFile
awk '{sum += $10}END{print sum}' InputFile >> SumFile
echo >> SumFile
sleep 10
done
# 7  
Old 05-19-2009
keep some counter inside while loop so that when that reach 10 get out of the loop
while [ $count -eq 10 ]
...
...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk/sed summation of one column based on some entry in first column

Hi All , I am having an input file as stated below Input file 6 ddk/djhdj/djhdj/Q 10 0.5 dhd/jdjd.djd.nd/QB 01 0.5 hdhd/jd/jd/jdj/Q 10 0.5 512 hd/hdh/gdh/Q 01 0.5 jdjd/jd/ud/j/QB 10 0.5 HD/jsj/djd/Q 01 0.5 71 hdh/jjd/dj/jd/Q 10 0.5 ... (5 Replies)
Discussion started by: kshitij
5 Replies

2. Shell Programming and Scripting

Summation of a particular column which are in different folders

I have three folders named f1, f2 and f3. The file names are same in all these folders. I would like to get the summation of the second column from all files. How can I do this ? file1 in f1 folder 143 143.69 60.2 81.30 40.4 62.39 166.3 83.38 107.2 60.30 37.5 144 192.62 107.9... (3 Replies)
Discussion started by: edisonjoe
3 Replies

3. Shell Programming and Scripting

Modification of Summation Script

hi guys, i have a script that basically just sums up the values of 2 particular columns in a file, grouped by the columns specified as well The script is quite long, but it's basically just repetitive.. just for each condition. This script only accepts one type of input file. ... (22 Replies)
Discussion started by: ramneim
22 Replies

4. Shell Programming and Scripting

Awk - Summation in Proper decimal Format

Hi I am executing below command to do summation on 46th coloumn. cat File1| awk -F"|" '{p += $46} END { printf"Column Name | SUM | " p}' I am getting output as Column Name | SUM | 1.01139e+10 Here I want output in Proper decimal format. Can someone tell me what change is required for same? (1 Reply)
Discussion started by: sanranad
1 Replies

5. Shell Programming and Scripting

calculating column summation in a directory of flat files

Hello Guru s I need your kind help to solve my below issue I have a directory of flat files and have to calculate sum of some columns from the flat file . Say for flat file 302 I need the column summation of 2 and 3 rd column For flat file 303 I need the column summation of 5 and... (2 Replies)
Discussion started by: Pratik4891
2 Replies

6. Shell Programming and Scripting

Summation of column value in flat file

Hello Guys Please find my below requirement I have a flat file with column headers in first line and data The structure like below col1 col2 col3 A 1 2 B 3 4 C 5 6 Say I have to take the summation of col2 (that will depend on the... (2 Replies)
Discussion started by: Pratik4891
2 Replies

7. Shell Programming and Scripting

How to shift values in new column after certain interval?

Hello everyone, my data is in a format as below a a a a a a a a a a a a a a a (8 Replies)
Discussion started by: jojo123
8 Replies

8. UNIX for Dummies Questions & Answers

summation of values coming in a row.

Hi All, I need to sum values in a row. eg: input is: sum,value1,value2,value3,.....,value N Required Output: sum,<summation of N values> Please help me... (1 Reply)
Discussion started by: MrGopal666
1 Replies

9. Shell Programming and Scripting

compare the interval of 2 numbers of input2with interval of several numbers of input1

Help plz Does any one have any idea how to compare interval ranges of 2 files. finding 1-4 (1,2,3,4) of input2 in input1 of same key "a" values (5-10, 30-40, 45-60, 80-90, 100-120 ). Obviously 1-4 is not one of the range with in input1 a. so it should give out of range. finding 30-33(31,32,33)... (1 Reply)
Discussion started by: repinementer
1 Replies

10. Shell Programming and Scripting

How to perfrom summation for particular delimited field?

Hi, Please help to share your thought about how to perfrom summation for particular delimited field, and output to the particular file based on -rw-r--r-- 1 abc other 3094 Oct 19 09:40 0132019832-ps5_online_cdrm.unl -rw-r--r-- 1 abc other 1588 Oct 19 09:47... (2 Replies)
Discussion started by: rauphelhunter
2 Replies
Login or Register to Ask a Question