Extract minimum values among 3 columns


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extract minimum values among 3 columns
# 1  
Old 06-26-2010
Extract minimum values among 3 columns

Hi.

I would like to ask for helps on extracting a minimum values among three columns using gawk in tab separator.

input file:
Code:
as1 10 20 30
as2 22 21 23
as3 300 391 567
as4 19 20 15

Output file:
Code:
as1 10
as2 21
as3 300
as4 15

I am extremely appreciate your helps and comments. Looking forward to hear from you. Thank you very much.

Amanda

Last edited by Franklin52; 06-26-2010 at 02:54 PM.. Reason: Please use code tags
# 2  
Old 06-26-2010
To give you an idea ...:

Code:
#!/bin/bash

while read LINE
do
  FIRST=$( echo $LINE | awk '{print $1}' )
  LOWEST=$( echo $LINE | awk '{print $2"\n"$3"\n"$4}' | sort | head -n 1 )
  echo "$FIRST $LOWEST" >> out.file
done < in.file

exit 0
# finis

Code:
[house@leonov] cat in.file
as1 10 20 30
as2 22 21 23
as3 300 391 567
as4 19 20 15
[house@leonov] bash code.bash
[house@leonov] cat out.file
as1 10
as2 21
as3 300
as4 15

# 3  
Old 06-26-2010
Dr. House, The code is working. Thank you very much for your helps.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract rows with different values at 2 columns

Hallo, I would need to extract only rows which has different value in the second and third column. Thank you very much for any advices Input: A 0 0 B 0 1 C 1 1 D 1 3 Output B 0 1 D 1 3 (4 Replies)
Discussion started by: kamcamonty
4 Replies

2. Shell Programming and Scripting

Output minimum and maximum values for replicates ID

Hi All I hope that someone could help me! I have an input file like this, with 4 colum(ID, feature1, start, end): a x 1 5 b x 3 10 b x 4 9 b x 5 16 c x 5 9 c x 4 8 And my output file should be like this: a x 1 5 b x 3 16 c x 4 9 What I would like to do is to output for each ID... (2 Replies)
Discussion started by: giuliangiuseppe
2 Replies

3. Programming

Computations using minimum values

I have the following code and into into trying to simplifying it. Any suggestions please? pmin = min (p(1), p(2), p(3), p(4), p(5), p(6)) ni = 0 xint = 0.0 yint = 0.0 zint = 0.0 !--------------------------------------------- ! if ((0.99999 * p(1)) <= pmin) then ... (3 Replies)
Discussion started by: kristinu
3 Replies

4. Shell Programming and Scripting

Extract minimum/maximum using awk

From the below table I want to print highest value and lowest value using awk script. aaa 55 66 96 77 ggg 22 96 77 23 ddd 74 58 18 3 kkk 45 89 47 92 zzz 34 58 89 92 Thanks, Green edit by bakunin: it sure is not news to you that you should use CODE-tags, no? And that we do not want such... (3 Replies)
Discussion started by: gwgreen1
3 Replies

5. Shell Programming and Scripting

Comparing the minimum values of a character in lines

Hello, I have files as follows: ACTGCCCTG ACCGGCTCC ACAAATTTC ACCCGGGTTI want to do the following: I want to find certain strings in each line, for example CT and TT. Then I want the script to give me the number of the characters before my string, for example, 6 for the first line, 5 for... (4 Replies)
Discussion started by: Homa
4 Replies

6. Shell Programming and Scripting

Print minimum and maximum values using awk

Can I print the minimum and maximum values of values in first 4 columns ? input 3038669 3038743 3037800 3038400 m101c 3218627 3218709 3217600 3219800 m290 ............. output 3037800 3038743 m101c 3217600 3219800 m290 (2 Replies)
Discussion started by: quincyjones
2 Replies

7. Shell Programming and Scripting

minimum and maximum from columns

Hi Friends, my input file is this way chr1 100 120 abc chr1 100 121 def chr1 100 122 ghi chr2 240 263 kil chr2 240 276 ghj chr2 255 290 hjh my output chr1 100 122 abc chr2 240 276 kil chr2 255 290 hjh Basically, I want to match on first and second column and then print the... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

8. Shell Programming and Scripting

Extract values from a matrix given the rows and columns

Hi All, I have a huge (and its really huge!) matrix about 400GB in size (2 million rows by 1.5 million columns) . I am trying to optimize its space by creating a sparse representation of it. Miniature version of the matrix looks like this (matrix.mtx): 3.4543 65.7876 54.564 2.12344... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

9. Programming

Select several minimum values from row (MySQL)

Hello there. I've got the query like that SELECT count(tour_id) AS cnt FROM orders JOIN tours ON orders.tour_id=tours.id GROUP BY tour_id The result Is cnt 1 4 2 1 1 Now i have to select all records with minimum values in field "cnt" MySQL function min() returns only one.... (2 Replies)
Discussion started by: Trump
2 Replies

10. Shell Programming and Scripting

Count minimum columns in file

Hi All, Consider the file with following lines: 1,2,3,4 1,2,3, 5,6,7,7,8,9 1 I need to get the count of minimum columns per line. i.e. in above case, it should come out to be 1 since the last line only has 1 column. I tried following code: minCount = 0 wordCountPerLine = 0... (12 Replies)
Discussion started by: sh_kk
12 Replies
Login or Register to Ask a Question