HELP Script don't work selecting lowest value!!!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers HELP Script don't work selecting lowest value!!!
# 1  
Old 04-24-2012
Question HELP Script don't work selecting lowest value!!!

Hy again guys,

Last week i resolve a question here but now i need your help again Smilie

I have about 3000 files that i need to choose based on the lowest value, so i make temp files like this:
Quote:
ZINC00001995_0 -5.00040
ZINC00001995_1 -3.03547
The files can have lines from 1-10 but only 2 columns, the point is to grep the name os the file in 1st column based in lowest value of 2nd collumn

For select the line with lowest value i use in a bash script this line:
Code:
nomepose=(`awk '{if ($2 < min) {min=$2; minline=$0}} END {print minline}' $awkvar | awk '{print $1}'`)

As a awk variable to get me the name of file. But after i execute the script i found that some files have positive values like this:
Code:
ZINC03391611_0 0.18602
ZINC03391611_1 3.41902

So when i try that line the script cant copy the name of file with lowest value in this case should had print "ZINC03391611_0" but don't print nothing.

I try some variations in this awk but without sucess.

So how can i make the awk to get me always the lowest value even if the value is positive?! Smilie

Thanks
# 2  
Old 04-24-2012
try this Smilie
Code:
# awk '$2~!/^-/{if(NR==1){min2=$2;min=$0;next}{if(min2>$2)min=$0}}END{print min}' infile

# 3  
Old 04-24-2012
Quote:
Originally Posted by ygemici
try this Smilie
Code:
# awk '$2~!/^-/{if(NR==1){min2=$2;min=$0;next}{if(min2>$2)min=$0}}END{print min}' infile


Thanks for your reply, in last hour i was try the line you gave me because that line don't get me all files only fews. I'm new in script and after some trys i get this that work:
Code:
awk '{if (NR==1){min2=$2; min=$0;next}{if (min2>$2) min=$0}} END {print min}' infile | awk '{print $1}'

The problem is that there are some files that only have 1 column like this:
Quote:
ZINC03862582_0
ZINC03862582_1
In this case i DON'T whant the line because there are no value and the awk that i use give me always the low line how can i define the awk for only print the 1st column if there is value in the 2nd?

For what i read about awk i think the 1st part in your line
Code:
$2~!/^-/

is for tell to the awk the tipe of the 2nd column right?

About the
Code:
(NR==1)

i know this is "The Number of Records Variable" can you please tell me what this do?

Thanks againSmilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting lowest and highest values in columns 1 and 2, based on subsets in column 3

Hi, I have a file with the following columns: 361459 447394 CHL1 290282 290282 CHL1 361459 447394 CHL1 361459 447394 CHL1 178352861 178363529 AGA 178352861 178363529 AGA 178363657 178363657 AGA Essentially, using CHL1 as an example. For any line that has CHL1 in... (2 Replies)
Discussion started by: hubleo
2 Replies

2. Solaris

Open Terminal Don't work

Hi, I installed solaris 10 x86 on my local system. it was working fine. today when i started the system, it started up without any problem. when i tried to open the terminal it didn't open any terminal. Plz help me (0 Replies)
Discussion started by: malikshahid85
0 Replies

3. Solaris

I don`t understand how It work (about startup script)?

Hi all. The startup script in /usr/local/bin. After user login the script run an application. Iwould in the same way run the another application. How to make It similar? Where I must to look? Regards. (3 Replies)
Discussion started by: wolfgang
3 Replies

4. HP-UX

awk don't work in hp-ux 11.11

Hello all! I have problem in hp-ux 11.11 in awk I want to grep sar -d 2 1 only 3 column, but have error in awk in hp-ux 11.11 Example: #echo 123 234 | awk '{print $2}' 123 234 The situattions in commands bdf | awk {print $5}' some... In hp-ux 11.31 - OK! How resolve problem (15 Replies)
Discussion started by: ostapv
15 Replies

5. Programming

why printf don't work?

I use Solaris 10, I use following code: #include <signal.h> int main(void){ printf("----------testing-----------"); if(signal(SIGUSR1,sig_usr)==SIG_ERR) err_sys("can't catch SIGUSR1"); for(;;) pause(); sig_user(int signo){ ..... } when I run above code,it print nothing... (3 Replies)
Discussion started by: konvalo
3 Replies

6. Programming

why daytime don't work?

Following code is detecting solaris daytime,when I run it,I can't get any result,code is follows: #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFFSIZE 150 int main(){ ... (2 Replies)
Discussion started by: konvalo
2 Replies

7. Shell Programming and Scripting

Script to move files based on Pattern don't work

Hi people, i need you help on this if you can. I have a script that does the move command when it searches for a that doesn't match the pattern. This Pattern is on a list. When it run's and doesn´t found no files but it haves 2 more folders it moves the folders too. Ex:... (1 Reply)
Discussion started by: osramos
1 Replies

8. Shell Programming and Scripting

find options don't work in script

Hi, I'm trying to write a bash script to find some files. However it seems that the find command is not behaving the same way when the script is executed as it does when executed from the command line: Script extract: #!/bin/bash ... NEW="/usr/bin/find current/applications/ -name '*jar'... (3 Replies)
Discussion started by: mattd
3 Replies

9. UNIX for Advanced & Expert Users

variables don't work for inline "su" script

My first post here... I cannot get variables to work when using inline KSH commands on a "su" command. I have a KSH script, below, that produces my problem: #!/usr/bin/ksh su <user_id> <<-END export FLD1=`echo $PWD` pwd echo $FLD1 echo TEST echo $PWD END The script will prompt me... (3 Replies)
Discussion started by: joekreif
3 Replies

10. Post Here to Contact Site Administrators and Moderators

How come sigs don't work?

They appear to be turned on, I entered mine in. The check boxes are all checked. And yet, no sigs? (4 Replies)
Discussion started by: l008com
4 Replies
Login or Register to Ask a Question