vendredi 27 novembre 2020

awk syntax '||' without 'if' - how does it work and why does it loop?

I've been doing this university class and we got an assignment about awk. One exercise was to find the lowest value of a column, and I stumbled upon this line of code:

awk 'NR == 1 || $3 < min {line = $0; min = $3}END{print line}' file.txt

If number of lines read = 1 OR Element in third column is smaller than min, set line = line being read and min = Element from third column STOP print line.

I only know some basic python so far and I do not understand how the || works in this context. I know that it is a logical OR, but why is there no if?

Why does it loop without explicit commands like while, until or for?

Does END equals something like else in an if statement?

Aucun commentaire:

Enregistrer un commentaire