Help with compare two column and print out column with smallest number

Input file :

5 20
500 2
20 41
41 0
23 1

Desired output :

5 
2 
20
0
1

By comparing column 1 and 2 in each line, I hope can print out the column with smallest number.

I did try the following code, but it don't look good :frowning:

awk '$1<$2{print $1}' input_file
5
20
awk '$2<$1{print $2}' input_file
2
0
1

Thanks for any advice.

awk '{print $1<$2?$1:$2}' file
2 Likes

Nice Subbeh. It is better to add parentheses, since some awks regard the comparison as ambiguous:

awk '{print ($1<$2)?$1:$2}' file

or

awk '{print ($1<$2?$1:$2)}' file
2 Likes