Finding minimum value

Hi All,

I have multiple files which contains 5 columns and multiple rows.....

I want to calculate the minimum value of column 5th, if column 2 is MET, till column 1 comes to the next number.

Also it must skip the condition similar to 1st line where column number 1 and 3 are same and the value in column five is zero.

the output should be:

likewise for every other string (there are total 20 different strings)

Any help is appreciated.

Thanks in advance.

nawk 'BEGIN{FS=' ';mval=$5;n=$1;i=0;val=0;}$1 !~ $3 & $2 ~ /MET/{if(n != $1){print $1 " " mval; }if($5 < mval){mval=$5}}'  ur_file_name

Cheers,
Ranga:-)

hi Ranga,

Its showing an error......

Use awk instead of nawk

Cheers,
Ranga:-)

Hi ranga,

awk is also showing error

Put your strings ALA, ASD, etc all in one file, one per line. Let's call this file 'strings'.
Then you can do:

while read aa ; do 
  awk '$2=="'$aa'" && !($1==$3 && $5==0){print}' input | sort -nk5 
done < strings
1 Like

Hi mirni,

Ur code works well.....:b:
but as I want to run this code on multiple files....i need to save this printed data of each file in their corresponding output file for further analyses. Iam using the following code :

But the output file is completely blank...without any data....However, the code is giving the desired output if data is not transfered to the new output file.

No need for 'paste'; that tool is used to merge lines. I assume the file liist has the filenames to be processed, one per line, right?
The redirection operator you have there, '>' will truncate the output file on every iteration of strings. Use '>>' instead to append; or do the redirection at the end:

while read line;  do
  while read aa ; do
    awk '$2=="'$aa'" && !($1==$3)' $line
  done < strings > ${line}new
done < liist

You can get rid of the outer shell loop and process all files with awk, and print into the file from awk. Much more efficient. Like this:

while read aa ; do
  awk '$2=="'$aa'" && !($1==$3){print >> FILENAME"new"}' `cat liist`
done < strings
1 Like

Thanks a lot mirni......I got the results :slight_smile:

it works well....

Hi,

I am facing one more problem in this......
In the above case, lets say the "strings" list contains 20 strings which are scanned in the original file. If in original file, any three random strings are missing, the immediate next will be printed (i.e, out of 20, only 17 are printed continuously) but I dont want to skip the whole row...instead of that i wanna print "Absent" in each column of that missing row....

Can any one help me for this....