Print smallest negative number with corresponding index from a column | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Print smallest negative number with corresponding index from a column

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-14-2013
Birda Birda is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 16 March 2013, 4:40 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Print smallest negative number with corresponding index from a column

considering the following table:

Code:
ID          col1            col2                 col3               col4
1    -16.06801249     13.49785832   -56.57087607      -27.00500526
2     -1.53315720      0.71731735    -42.03602078      -39.78554623
3     -1.53315190      0.71731587    -42.03601548      -39.78554771
4     -1.53316243      0.8731724    -42.53602760        -39.85545910 
5     -16.  6533188    13.7606723    -42.03605186      -27.06753555

how to print (using sed or awk or ...): the smallest negative number from col4 that has value less than 1.0 in col2 (like 0.71731735, 0.8731724, etc but not 13.49785832 or 13.7606723)
expected result looks like:


Code:
ID          col2                    col4                 
2           0.71731735         -39.78554623

I appreciate for any idea
Birda

Last edited by Scrutinizer; 02-14-2013 at 03:09 AM.. Reason: code tags
Sponsored Links
    #2  
Old 02-14-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 31 October 2014, 5:50 PM EDT
Location: Amsterdam
Posts: 9,562
Thanks: 286
Thanked 2,430 Times in 2,177 Posts
Hi what have you tried so far? Where are you stuck?
Sponsored Links
    #3  
Old 02-14-2013
Birda Birda is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 16 March 2013, 4:40 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re:

Hi, I tried

Code:
awk 'NR == 1 || $4 < min {line = $0; min = $4}END{print line}' xample1.awk

or
Code:
sort -nk 4 xample1.awk | head -n 1

but I have problem how to consider for the 2nd column for values containing <1.0. only values containing 0.* in col2 should be considered while comparing the smallest values in col4.

what about using sed?
thank you

Last edited by Scrutinizer; 02-14-2013 at 06:19 AM.. Reason: code tags
    #4  
Old 02-14-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 31 October 2014, 5:50 PM EDT
Location: Amsterdam
Posts: 9,562
Thanks: 286
Thanked 2,430 Times in 2,177 Posts
How about combining it with the other test:

Code:
awk '$3<1 && $5<m { m=$5; s=$1 OFS $3 OFS $5 } END{ print s }' file

(BTW, col4 = $5)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Taking largest (negative) number from column of coordinates and adding positive form to every other crunchgargoyle Shell Programming and Scripting 13 10-05-2011 07:46 PM
Help with find highest and smallest number in a file with c cpp_beginner Programming 2 07-24-2011 10:30 PM
How to print column based on row number Surabhi_so_mh Shell Programming and Scripting 2 12-31-2010 12:45 AM
How to print largest and smallest number. amp10388 UNIX for Dummies Questions & Answers 2 05-07-2008 10:28 AM
checking the smallest and largest number subin_bala Shell Programming and Scripting 4 04-24-2008 07:32 AM



All times are GMT -4. The time now is 08:25 PM.