Sponsored Content
Top Forums UNIX for Dummies Questions & Answers get max value every 4 rows between 2 column Post 302673437 by alister on Wednesday 18th of July 2012 12:54:21 AM
Old 07-18-2012
Your sample data looks to me to have 4 columns, not 2 (in the future, please use code tags around data to preserve formatting).

Untested:
Code:
awk '$4 > max { max = $4; s = $0 } NR % 4 == 0 { max = 0; print s }' data.txt

If that code helps in finding a cure to some dreadful disease, I expect free treatment if I ever contract it. Smilie

Regards and welcome to the forum,
Alister

Last edited by alister; 07-18-2012 at 02:00 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

loop in awk - column max for each column

Hello all, this should really be easy for you... I need AWK to print column maxima for each column of such input: Input: 1 2 3 1 2 1 1 3 2 1 1 2 Output should be: 2 2 3 3 This does the sum, but i need max instead: { for(i=1; i<=NF; i++) sum +=$i } END {for(i=1; i in sum;... (3 Replies)
Discussion started by: irrevocabile
3 Replies

2. Programming

Getting Rows from a MySQL Table with max values?

I feel stupid for asking this because it seems that MYSQL code isn't working the way that I think it should work. Basically I wrote code like this: select * from `Test_DC_Trailer` HAVING max(DR_RefKey); Where the DR_RefKey is a unique numeric field that is auto iterated (like a primary key)... (7 Replies)
Discussion started by: Astrocloud
7 Replies

3. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

4. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Deleting all rows where the first column equals the second column

Hi, I have a tab delimited text file where the first two columns equal numbers. I want to delete all rows where the value in the first column equals the second column. How do I go about doing that? Thanks! Input: 1 1 ABC DEF 2 2 IJK LMN 1 2 ZYX OPW Output: 1 2 ZYX OPW (2 Replies)
Discussion started by: evelibertine
2 Replies

7. Shell Programming and Scripting

Get the MAX value out of a column

I've the following data set. I would like to look at the column 3 and only use the rows which has the max value for column 3 Can we use the awk or sed to achieve it. 10 2 10 100 11 2 20 100 12 2 30 100 13 2 30 100 14 ... (7 Replies)
Discussion started by: rudoraj
7 Replies

8. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

9. Shell Programming and Scripting

Median and max of duplicate rows

Hi all, plz help me with this, I want to to extract the duplicate rows (column 1) in a file which at least repeat 4 times. then I want to summarize them by getting the max , mean, median and min. The file is sorted by column 1, all the repeated rows appear together. If number of elements is... (5 Replies)
Discussion started by: ritakadm
5 Replies

10. Shell Programming and Scripting

Get min and max value in column

Gents, I have a big file file like this. 5100010002 5100010004 5100010006 5100010008 5100010010 5100010012 5102010002 5102010004 5102010006 5102010008 5102010010 5102010012 The file is sorted and I would like to find the min and max value, taking in the consideration key1... (3 Replies)
Discussion started by: jiam912
3 Replies
mlib_MatrixMaximum_U8(3MLIB)				    mediaLib Library Functions				      mlib_MatrixMaximum_U8(3MLIB)

NAME
mlib_MatrixMaximum_U8, mlib_MatrixMaximum_S8, mlib_MatrixMaximum_S16, mlib_MatrixMaximum_S32, mlib_MatrixMaximum_F32, mlib_MatrixMaxi- mum_D64 - find the maximum value in a matrix SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_MatrixMaximum_U8(mlib_u8 *max, const mlib_u8 *x, mlib_s32 m, mlib_s32 n); mlib_status mlib_MatrixMaximum_S8(mlib_s8 *max, const mlib_s8 *x, mlib_s32 m, mlib_s32 n); mlib_status mlib_MatrixMaximum_S16(mlib_s16 *max, const mlib_s16 *x, mlib_s32 m, mlib_s32 n); mlib_status mlib_MatrixMaximum_S32(mlib_s32 *max, const mlib_s32 *x, mlib_s32 m, mlib_s32 n); mlib_status mlib_MatrixMaximum_F32(mlib_f32 *max, const mlib_f32 *x, mlib_s32 m, mlib_s32 n); mlib_status mlib_MatrixMaximum_D64(mlib_d64 *max, const mlib_d64 *x, mlib_s32 m, mlib_s32 n); DESCRIPTION
Each of these functions finds the maximum value of all elements in a matrix. It uses the following equation: max[0] = MAX{ x[i] i = 0, 1, ..., (m*n - 1) } PARAMETERS
Each of the functions takes the following arguments: max Pointer to the maximum value. x Pointer to the first element of the source matrix. m Number of rows in the source matrix. n Number of columns in the source matrix. RETURN VALUES
Each of the functions returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_MatrixMinimum_U8(3MLIB), mlib_VectorMaximum_U8(3MLIB), mlib_VectorMinimum_U8(3MLIB), attributes(5) SunOS 5.10 10 Nov 2004 mlib_MatrixMaximum_U8(3MLIB)
All times are GMT -4. The time now is 09:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy