HHow to print the group with a highest value within a set


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HHow to print the group with a highest value within a set
# 1  
Old 06-12-2017
HHow to print the group with a highest value within a set

How to print the names with a highest value within a set and filter if it is the only unique group within the same set

input

Code:
sets    names    value    groups
j007    shot1    0.6    a
j007    shot2    0.5    b
j007    shot3    0.4    bb
j007    shot4    0.3    bc
j007    shot5    0.2    cd
j008    shot1    0.4    a
j008    shot2    0.3    ab
j009    shot1    0.14    a
j009    shot2    0.13    b
j009    shot3    0.12    bc
j010    shot1    22    a
j010    shot2    19    b
j010    shot3    5    bcd
j011    shot1    5    a
j011    shot2    2    b
j011    shot3    3    c

output

Code:
j007    shot1    0.6    a
j009   shot1   0.14 a
j010    shot1    22    a

Tried
Code:
sort -k 3,3 input | awk '$3*$3>A[$1]*A[$1]{A[$1]=$0} END{for(i in A) print i,A[i]}'  | sort -k 1,1


Last edited by quincyjones; 06-12-2017 at 05:00 PM..
# 2  
Old 06-12-2017
Clarification added.

Last edited by rdrtx1; 06-13-2017 at 06:31 PM..
# 3  
Old 06-12-2017
Thanks. But the group has to be always unique. Sorry maybe I didn't explain well. For example, first, the group with highest score 'a' should be unique. Means no ab or abc etc. Therefore j008 is not in the output. Second, there should be no other group that should be unique with in the same set. For example, j011 has 3 unique groups. Therefore it should not be in output. Hope that's clear? With your script, j009 is missing and j010 with wrong group is being selected.

Last edited by quincyjones; 06-12-2017 at 05:35 PM..
# 4  
Old 06-12-2017
The output was changed.

Last edited by rdrtx1; 06-12-2017 at 08:21 PM..
# 5  
Old 06-12-2017
Yes that's correct. I forgot to include j009 in the output earlier. My apologies.
# 6  
Old 06-12-2017
For my understanding, let me paraphrase your request:
In any set, look for the maximum value Col 3). These are listed below:

Code:
sets    names   value   groups  other_groups
j007    shot1   0.6     a       b bb bc cd
j008    shot1   0.4     a       ab
j009    shot1   0.14    a       b bc
j010    shot1   22      a       b bcd
j011    shot1   5       a       b c

Now, if the group(s) of this entry show up in any of the other entries of the same set, suppress this record. If so, ALL entries EXCEPT j008 should be printed, no?

Sorry, you crossposted while I was pondering. So - to be eliminated, the group has to be unique, i.e.one single letter, and this letter may not occur in any of the other, possibly multiletter, groups it the same set, nor may any other single letter group occur in that set?

Last edited by RudiC; 06-12-2017 at 06:13 PM..
# 7  
Old 06-13-2017
@RudiC: First part is correct. Second part noy exactly. If you do Venn diagram with the letters in the groups of a specific set, you should always see 'a' as a separate group. For example, j007 has this type but not j008. Next, though j009, j010, j011 have 'a' as a separate group, j011 has also 'b' and 'c' as separate groups. Therefore only j007, j009 and j010 are in the output.

---------- Post updated at 04:18 PM ---------- Previous update was at 04:17 PM ----------

@RudiC: Update: yes your update is correct. Sorry for the confusion.

---------- Post updated 06-13-17 at 02:34 AM ---------- Previous update was 06-12-17 at 04:18 PM ----------

@rdrtx1: It is still not working I think. For ex, when I ran the modified script on this input, it not suppose to print 'j007' but instead it prints with group 'a'. This should not be printed because there is another unique group ('e') in the data.

Code:
sets    names    value    groups
j007    shot1    0.6    a
j007    shot2    0.5    b
j007    shot3    0.4    bc
j007    shot4    0.3    c
j007    shot5    0.2    cd
j007    shot6    0.1    e


Last edited by quincyjones; 06-13-2017 at 06:00 AM..
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 print line with highest value

grepping on a value but then want to print only those lines that have the highest value in the 4th column log text text R59FJ log text text R63FT log text text R60JX log1 text text R63EA log1 text text R60JX desired output log text text R63FT log1 text text R63EAtried this but not getting... (2 Replies)
Discussion started by: jimmyf
2 Replies

2. Shell Programming and Scripting

Print whole line with highest value from one column

Hi, I have a little issue right now. I have a file with 4 columns test0000002,10030010330,c_,218 test0000002,10030010330,d_,202 test0000002,10030010330,b_,193 test0000002,10030010020,c_,178 test0000002,10030010020,b_,170 test0000002,10030010330,a_,166 test0000002,10030010020,a_,151... (3 Replies)
Discussion started by: Ebk
3 Replies

3. AIX

Print whole line with highest value from one column

Hi, I have a little issue right now. I have a file with 4 columns test0000002,10030010330,c_,218 test0000002,10030010330,d_,202 test0000002,10030010330,b_,193 test0000002,10030010020,c_,178 test0000002,10030010020,b_,170 test0000002,10030010330,a_,166 test0000002,10030010020,a_,151... (2 Replies)
Discussion started by: Ebk
2 Replies

4. Shell Programming and Scripting

Need to print duplicate row along with highest version of original

There are some duplicate field on description column .I want to print duplicate row along with highest version of number and corresponding description column. file1.txt number Description === ============ 34567 nl21a00is-centerdb001:ncdbareq:Error in loading init 34577 ... (7 Replies)
Discussion started by: vijay_rajni
7 Replies

5. Shell Programming and Scripting

Print the key with highest value

print the key with highest value input a 10 a 20 a 30 b 2 b 3 b 1 output a 30 b 3 (9 Replies)
Discussion started by: quincyjones
9 Replies

6. Shell Programming and Scripting

Only print the entries with the highest number?

Just want to say this is great resources for all thing Unix!! cat tmp.txt A 3 C 19 A 2 B 5 A 1 A 0 C 13 B 9 C 1 Desired output: A 3 B 9 C 19 The following work but I am wondering if there is a better way to do it: (4 Replies)
Discussion started by: chirish
4 Replies

7. UNIX for Dummies Questions & Answers

Print line with highest value from one column

Hi everyone, This is my first post, but I have already received a lot of help from the forums in the past. Thanks! I've searched the forums and my question is very similar to an earlier post entitled "Printing highest value from one column", which I am apparently not yet allowed to post a... (3 Replies)
Discussion started by: dliving3
3 Replies

8. UNIX for Dummies Questions & Answers

Print line with highest value from one column

Hi everyone, This is my first post, but I have already received a lot of help from the forums in the past. Thanks! I've searched the forums and my question is very similar to an earlier post entitled "Printing highest value from one column", which I am apparently not yet allowed to post a... (1 Reply)
Discussion started by: dliving3
1 Replies

9. Shell Programming and Scripting

Sort the file contents in each group....print the group title as well

I've this file and need to sort the data in each group File would look like this ... cat file1.txt Reason : ABC 12345-0023 32123-5400 32442-5333 Reason : DEF 42523-3453 23345-3311 Reason : HIJ 454553-0001 I would like to sort each group on the last 4 fileds and print them... (11 Replies)
Discussion started by: prash184u
11 Replies

10. Shell Programming and Scripting

Perl ? - How to find and print the lowest and highest numbers punched in by the user?

. . . . . . (3 Replies)
Discussion started by: some124one
3 Replies
Login or Register to Ask a Question