|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Hi what have you tried so far? Where are you stuck?
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Re:
Hi, I tried Code:
awk 'NR == 1 || $4 < min {line = $0; min = $4}END{print line}' xample1.awkor 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
|
||||
|
||||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|