Let's consider the following example
TRPA68W 0
TRPA68G 4.07199
TRPA68A 4.04406
TRPA68L 4.0284
TRPA68V 4.65386
TRPA68I 4.70191
TRPA68P 2.33544
TRPA68R 4.24453
TRPA68T 4.45232
TRPA68S 4.1945
TRPA68C 5.18104
TRPA68M 3.48962
TRPA68K 4.83645
TRPA68E 3.1922
TRPA68Q 4.65744
TRPA68D 3.68171
TRPA68N 0.42
TRPA68W 0
TRPA68Y 3.89335
TRPA68F 3.72391
TRPA68e 4.08042
I want to get the output as
0
So how to obtain the minimum value only?
I tried to do it using the following command
awk '{ for(i=1; i<=NF; i ) if((!MIN)||($i < MIN)) MIN=$i } END { print MIN }' filename
However it doesn't give desired output.
Can anybody please let me know what mistake I'm making?
CodePudding user response:
mawk '{ _= (__=$NF)< _ ? __:_ } END { print _ }'
0
CodePudding user response:
Who told you this is a silly question?
Here's a proposal for a solution:
cat test.txt | awk '{print $2}' | sort -n | head -n 5
Obviously, you need to replace head -n 5
by head -n 1
(the five is just for showing you how it works).
Some explanation:
awk '{print $2}
only shows you the second column of your file.
sort -n
means that the sorting must be done numerically.