finding least out of selected lines

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding least out of selected lines
# 1  
Old 09-01-2011
finding least out of selected lines


I have a file, which looks like:

1 PRO 3 ILE 6.816858
2 GLN 4 THR 6.763534
3 ILE 5 LEU 6.659603
4 THR 6 TRP 5.887478
5 LEU 7 GLN 5.224145
6 TRP 4 THR 5.887478
7 GLN 5 LEU 5.224145
8 ARG 10 LEU 5.922154
9 PRO 23 LEU 5.841176
10 LEU 23 LEU 4.665862
11 VAL 22 ALA 5.404240
12 THR 21 GLU 4.437617
13 ILE 66 ILE 4.792131
14 LYS 19 LEU 4.804988
15 ILE 17 GLY 5.244380
16 GLY 18 GLN 5.444090
17 GLY 15 ILE 5.244380
18 GLN 15 ILE 5.435863
19 LEU 14 LYS 4.804988
20 LYS 13 ILE 5.280103
21 GLU 12 THR 4.437617
22 ALA 83 ASN 4.773669
23 LEU 10 LEU 4.665862
24 SER 85 ILE 5.104049
25 ASP 86 GLY 5.401655
26 THR 28 ALA 5.716655
I want to print the row containg "PRO" in second column after comparing and finding the minimum value of fifth column present in all "PRO". and likewise for every other string present in second column.

I am using :
while read line
awk '{print $2,"\t"$5,"\t"$1,"\t"$3,"\t"$4}' $line | sort | uniq | awk '{if ($1 != prev_1 && $2 != prev_2){print}; prev_1=$1; prev_2=$2}' > $line"20m"

I am getting results, but I didnt understand this command....
and if there is only one string like "SER" in 2nd row, it is not printed in output file. Whereas, I want to have all strings with minimum fifth column.
Can any one plz suggest me for the same. or make me understand the command ??????
# 2  
Old 09-01-2011
awk '!a[$2]{a[$2]=$0;m[$2]=$5}$5<m[$2]{a[$2]=$0;m[$2]=$5}END{for (i in a) print a[i]}' file

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 09-01-2011
Well, use shell or awk, not both.

sed '
  /^[0-9]* PRO /!d
  s/.* //
 ' your_file |sort -nu | read key5
grep "^[0-9]* PRO .* $key5$" your_file

The file name of a list of file names file goes into a variable, that file is made stdin for the rest of the script, each line is read into a line variable, awk is called for that file name to rearrange the fields using tab separators, it is sorted left to right (not numeric, 10 may be less than 9, made unique (sort does that better with a u), fed to a second awk that test the first two fields against saved prior 2 fields, only prints the first for any set of values, with output to a file with same name suffix 20m.
This User Gave Thanks to DGPickett For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting selected lines in a file

Hi Guys , I have two files say a1 and a2 having following contents a1 dag wfd a2 dag wfd chire hcm I want to delete only the lines in a2 which are in a1 and final output of a2 should be a2 chire hcm (6 Replies)
Discussion started by: Pradeep_1990
6 Replies

2. Shell Programming and Scripting

Selected matching lines

two files: one with the line number only, and the 2nd one with line number and content, as following: line_file.txt 1 3 5 9 23 30 content_file.txt 1|we are the world|good|great 2|easily do this by highlighting you|easily do this by highlighting you|easily do this by highlighting... (2 Replies)
Discussion started by: dtdt
2 Replies

3. Shell Programming and Scripting

Delete selected lines

hi Gurus, I have a source file with more than 10 columns ( not fixed ) I want to delete all the lines on the following condition 1) where i have first column as "UPDATE PLAN ADD RATE SCHEDULE" and fourth column as null awk '($1=="UPDATE PLAN ADD RATE SCHEDULE" && $4=="") {print $0}'... (5 Replies)
Discussion started by: r_t_1601
5 Replies

4. Shell Programming and Scripting

Reading selected lines from a param file

Hi all, I have a question for the Gurus. I apologize if this has bee shared before but I couldn't find the link. I am trying to read parameters from an external parameter file. What I m trying to achieve is read selected lines from an external parameter file into the script. for eg my param... (4 Replies)
Discussion started by: maverick1947
4 Replies

5. Shell Programming and Scripting

trying to print selected fields of selected lines by AWK

I am trying to print 1st, 2nd, 13th and 14th fields of a file of line numbers from 29 to 10029. I dont know how to put this in one code. Currently I am removing the selected lines by awk 'NR==29,NR==10029' File1 > File2 and then doing awk '{print $1, $2, $13, $14}' File2 > File3 Can... (3 Replies)
Discussion started by: ananyob
3 Replies

6. Shell Programming and Scripting

Process selected lines

I have an if statement where I state that if there are more than one records (lines) found containing a string in a file, then it enters into a while loop to use each line for as many lines as there are and then stop. Trouble is, I can't figure out how to move to the next instance of each line. ... (2 Replies)
Discussion started by: derekphl
2 Replies

7. UNIX for Dummies Questions & Answers

Copy selected lines in vim

Hi, I am looking to copy selected lines from a file using the vim editor. I have looked up a few resources and they have suggested to use this- Type mk Type: "ay'k (double quotes, <register name from a-z>, <y-yank single quote, k You can paste those lines wherever you want with "ap I tried... (7 Replies)
Discussion started by: coolavi
7 Replies

8. Shell Programming and Scripting

concatenating selected lines of multiple files

Hi, I would like a shell script that reads all files in a directory and concatenate them. It is not a simple concatenation. The first few lines of the files should not be included. The lines to be included are the lines from where 'START HERE' appears up to the end of the file. For example, I... (4 Replies)
Discussion started by: laiko
4 Replies

9. UNIX for Dummies Questions & Answers

extracting selected few lines through perl

How can I extract few lines(like 10 to 15, top 10 and last 10) from a file using perl. I do it with sed, head and tail in unix scripting. I am new to perl. Appreciate your help. (2 Replies)
Discussion started by: paruthiveeran
2 Replies

10. Shell Programming and Scripting

print selected lines

Hi everybody: I try to print in new file selected lines from another file wich depends on the first column. I have done a script like this: lines=( "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "21" "31" "41" "51" "55" "57" "58" ) ${lines} for lines in ${lines} do awk -v ... (6 Replies)
Discussion started by: tonet
6 Replies
Login or Register to Ask a Question