Help In fetching the 2nd Peak value of a column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help In fetching the 2nd Peak value of a column
# 1  
Old 12-09-2011
Help In fetching the 2nd Peak value of a column

Hi,

We have a requirement of calculating the AVG, Peak and 2nd Peak (Say Peak2) of a column in a text file. We are able to get Avg and Peak but we are finding difficulty in getting the 2nd Peak. I tried using the AWK but in vainL. Please find the below Script i have written for fetching AVG and Peak.

Code:
#!/usr/bin/bash

Peak=` cat temp.txt | awk '{ if (($1) > max) max = ($1) } END { print max }'`
echo "Peak value of metrics:" $Peak

Avg=`cat temp.txt | awk '{sum+=$6} END { print sum/NR}'`
echo "Avg value is:" $Avg

Code:
bash-3.00$ cat temp.txt
1 S 3 F 4 78
22 F 33 D 6 67
12 W 1 T 15 86

I want to fecth the 2nd Peak fromtemp.txt. We tried using the $Peak as well. But we failed to achieve 2nd Peak for temp.txt.Request you to help on this.

Its a bit urgent

Last edited by Scott; 12-09-2011 at 07:00 AM.. Reason: Please use code tags, and less formatting and post in the appropriate forum
# 2  
Old 12-09-2011
Is this what you're looking for? The following one-liner will print 2nd peak of first column.
Code:
$ awk '{print $1}' temp.txt | sort -nr | sed -n 2p
12

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 12-09-2011
Thanks!!

Thanks balajesuri.. Thats really Great stuff!!Smilie
# 4  
Old 12-09-2011
Code:
 
perl -lane 'push(@a,$F[0]); END{$b=(sort @a)[-2]; print $b}' input.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Peak Ram Usage

grpdsku program allows user to check their group disk space in a server environment. The data in the dialog box queries a text file. Each text file is labeled with a current timestamp. Results output to a msgbox. Also, results output to a csv file. The csv file is sent to the user via email ... (13 Replies)
Discussion started by: dellanicholson
13 Replies

2. UNIX for Beginners Questions & Answers

Fetching 1st Column and Last n Columns

I am trying to fetch 1st column and last 10 columns.The code I am using is working fine but after using the code then output file becomes space delimited not tab delimited. awk 'BEGIN {OFS="\t"}{printf("%s\t",$1)}{for(i=NF-9; i<=NF; i++) {printf("%s\t",$i)};printf "\n" } ' inputfile ... (11 Replies)
Discussion started by: Nina2910
11 Replies

3. Shell Programming and Scripting

Fetching values in CSV file based on column name

input.csv: Field1,Field2,Field3,Field4,Field4 abc ,123 ,xyz ,000 ,pqr mno ,123 ,dfr ,111 ,bbb output: Field2,Field4 123 ,000 123 ,111 how to fetch the values of Field4 where Field2='123' I don't want to fetch the values based on column position. Instead want to... (10 Replies)
Discussion started by: bharathbangalor
10 Replies

4. Shell Programming and Scripting

Fetching columns from .csv file except last column

Hi, i have below list of files so i just want the name of the files in one parameter and not the timestamp. i want only GIDW_Dy_Tm_Seg_Sls_legacy_PL_0_0_ in variable of all files. GIDW_Dy_Tm_Seg_Sls_legacy_PL_0_0_20131001101800.csv GIDW_Dly_Sls_legacy_RO_0_0_20131001172001.csv ... (9 Replies)
Discussion started by: renuk
9 Replies

5. Shell Programming and Scripting

Transpose from 2nd column till the last column

Hi I have 5 columns like this a b c d e f g h i j k l m n o From 2nd column till the 5th column of every record, I would like to transpose them as rows, so my output file contains only one row a b c d e f g h i j (9 Replies)
Discussion started by: jacobs.smith
9 Replies

6. Shell Programming and Scripting

Calculate 2nd Column Based on 1st Column

Dear All, I have input file like this. input.txt CE2_12-15 3950.00 589221.0 9849709.0 768.0 CE2_12_2012 CE2_12-15 3949.00 589199.0 9849721.0 768.0 CE2_12_2012 CE2_12-15 3948.00 589178.0 9849734.0 768.0 CE2_12_2012 CE2_12-52 1157.00 ... (3 Replies)
Discussion started by: attila
3 Replies

7. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

8. Shell Programming and Scripting

comparing column of two different files and print the column from in order of 2nd file

Hi friends, My file is like: Second file is : I need to print the rows present in file one, but in order present in second file....I used while read gh;do awk ' $1=="' $gh'" {print >> FILENAME"output"} ' cat listoffirstfile done < secondfile but the output I am... (14 Replies)
Discussion started by: CAch
14 Replies

9. Shell Programming and Scripting

Average and peak System statistics

Hi I need to find the average and peak values of cpu usage, memory usage, and the peak time of occurences..in addition to that i need disk usage (free and used ) and (average and peak or total in a day)number of dropped packets in a interface i have tried using netstat -d -I eri0 and the... (0 Replies)
Discussion started by: aemunathan
0 Replies

10. Shell Programming and Scripting

Parse 1 column and add 2nd column

I'm racking my brain on this one! :( I have a list like this: Paul 20 Paul 25 Paul 30 Frank 10 Julie 15 Julie 13 etc, etc... I've been trying to figure out a way to have the output display the name in the first column ONCE and add the numbers in the second column and display that... (2 Replies)
Discussion started by: sdlennon
2 Replies
Login or Register to Ask a Question