Trouble with part of an exercise

Hi, 'm trying to do an exercicise, and one part is:

ls -l $1 | awk '
    BEGIN {
       max = $5;
    }
    {
       if ($5 > max){
          max = $5;
       }
    }
    END {
    print "Tamanio mayor fichero = " max; }'

# Imprimimos ahora el menor tama�o de fichero
ls -l $1 | awk '
    BEGIN {
       min = $5;
    }
    {
       if ($5 < min){
          min = $5;
       }
    }
    END {
    print "Tamanio menor fichero = " min; }'

Seek the maximum and minimum size of files that are to implement the command ls-l. The problem is that it shows me the right way to screen the most, but not the least, and more turns that I fail to see what could be the problem.

Thanks

To keep the forums high quality for all users, please take the time to format your posts correctly.

Use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)
Thanks.

The command of the BEGIN section executes before any input is read so the value of min is empty, to find the minimum size you can do something like this:

ls -l $1 | awk '
NR==2{
  min = $5; next
}
{
  if ($5 < min){
    min = $5;
  }
}
END {print "Tamanio menor fichero = " min; }'

Regards

Many thanks, it works !! But can u explain me why or what is NR == 2 ??? I don't understand :S

Many many thanks

The command reads the first value on the second line of the command ls -l. The first line is something like: total xxx.

Regards

Ok, it's finished !! Many thanks !