How to find the X highest values in a list depending on the values of another list with bash/awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find the X highest values in a list depending on the values of another list with bash/awk?
# 1  
Old 12-09-2013
How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone,




This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file):
Code:
ID, Code, Value, Store SP|01, AABBCDE, 15, 3  SP|01, AABBCDE, 14, 2  SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3  SP|02, AABBCED, 15, 2  SP|01, AABBCDF, 12, 3 SP|01, AABBCDD, 13, 2  SP|02, AABBCDF, 9, 2 SP|01, AABBCDF, 8, 3

The idea is to print rows with the 2 highest values in "Value" column for identical values in "Code" (And also keep the headers)
Exemple of output files:
Code:
ID Code Value Store SP|01, AABBCDE, 16, 3 SP|01, AABBCDE, 15, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDD, 13, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDF, 12, 3

I'm new to Linux and have a bit of knowledge in very basic use of AWK, sed, grep ect but I'm unsure how to manipulate the file to get the output as stated above.


Any help would be very much appreciated!
# 2  
Old 12-09-2013
Hi you can use sort command to sort the data depending upon the column u wanted and then u get the top two example i have file new with random data

Code:
/var/backup # cat new1                                                            
1,2,3,4,5,6                                                                     
7,9,10,456,123                                                                  
8,123,678,900,100                                                               
/var/backup # sort -nrk2 -t, new1|head -2                                         
8,123,678,900,100                                                               
7,9,10,456,123                                                                  
/var/backup #

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find common values in python list in ordered format

Hello All, There are various codes available to find the intersection between two sets in python. But my case is the following: I want to find the continual common pattern in different lists compared to list1. (i have underlined the longest common patterns in set a and set b) a = 2, 3, 5,... (1 Reply)
Discussion started by: Zam_1234
1 Replies

2. Shell Programming and Scripting

awk to store in a list the values of certain fileds

Dear Group, I have following input: sa;sb;sc;sd;period;ma;mb;mc;md;me sa1;sb1;sc1;sd1;200001;ma1;mb1;mc1;md1;me1 sa2;sb2;sc2;sd2;200002;ma2;mb2;mc2;md2;me2 sa3;sb3;sc3;sd3;200003;ma3;mb3;mc3;md3;me3 first line contains the headers! I want to create with one pass the following output:... (8 Replies)
Discussion started by: suturjik
8 Replies

3. Shell Programming and Scripting

Sort and list values from CSV

I have a CSV with below values name,city,2,country name,city,15,country abc,wq,10,afdfd, qeqe,ewqre,1,wqew I need to sort them in ascending order based on the value of column 3 and then , pick the rows with values less than 10 and be able to display the columns in that row. Can anyone... (11 Replies)
Discussion started by: Nevergivup
11 Replies

4. Shell Programming and Scripting

Find and replace values using a list from a file

Hello Guys. I have a very big file where I need to change some values according a list on other file. The following file is were I have the values to be changed. The field where I need to replace the values is File_Nb : File1.txt Obs_Report_Result : # ===== (5)... (19 Replies)
Discussion started by: jiam912
19 Replies

5. UNIX for Dummies Questions & Answers

Specific values from a list, awk

Hello together! I have a list like this 1 3 2 5 3 7 4 2 Now I want to take the average of the second column and multiply it by the difference of the first and last value of the first column. I posted an similar thread, but now I wonder how I can tell awk in an easy way to take specific... (2 Replies)
Discussion started by: bjoern456
2 Replies

6. Shell Programming and Scripting

how do I list my values one per line instead of across it?

I want to list my vars in a script so they look like while read IN var1 var2 var3 var4 do echo $IN done Then in the same script have them read and processed. the closest I can get is as follows but this is obviously wrong. NOTE I want a list not all the entries on one line, that... (5 Replies)
Discussion started by: pobman
5 Replies

7. Shell Programming and Scripting

grep a list of values

Hi everybody! :) :D :D :) it's great to be here since this is my first post. touch /base/oracle/FRA/XMUT00/RMAN_FLAG touch /base/oracle/FRA/XRLL00/RMAN_FLAG find directory name containing RMAN_FLAG : $ find /base/oracle/FRA -name RMAN_FLAG -print|xargs -n1 dirname |sort -u... (3 Replies)
Discussion started by: jolan_louve
3 Replies

8. Shell Programming and Scripting

Search list of values

I have a file which contains a list of search values $cat my.txt FTIP002671604 FTIP002702940 FTIP002703183 FTIP002414805 And lots of such search values. I have to search these valus in the current directory. Can we do this one command wihtout writing a script. Regards, Rahul. (1 Reply)
Discussion started by: rahulrathod
1 Replies
Login or Register to Ask a Question