Skip to content
Advertisement

Print min and max with awk

Why wont this awk script work, where I want to print the min and max of an input by just reading the data once. I would also like to initialize the min and max variable with the first value of the data.

Say I have a file

JavaScript

I am using awk to print the min and max with:

JavaScript

But I am getting a result of:

JavaScript

I dont understand why min is set to blank?

Advertisement

Answer

The BEGIN {} block is processed before the first line so $2 is undefined.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement