Print smallest integer from file using awk custom function?

Bill bstanle at wowway.com
Fri Jan 8 16:19:18 UTC 2016



On 01/08/2016 09:23 AM, asad wrote:
> `awk` function looks like this in a file name `fun.awk`:
>
>
>     {
>
>     print f()
>     }
>     function f()
>
>     {
>
>
>     if(NR==1){s=$0}
>
>
>     if($0<p)
>
>     {s=$0}
>
>     {p=$0}
>
>      { return s}
>
>     }
>
> The contents of `awk.write`:
>
>     1
>     23
>     32
>
> The `awk` command is:
>
>     awk -f fun.awk awk.write
>
>
> but it print x3 times. why?
WS=> Of course this is not an answer to your question, but what do you 
mean by "smallest integer"?  Mathematically, there is no such thing as 
"smallest integer" because integers are infinite.  In computer science, 
it depends on how much space is set aside to represent integers.  Is it 
a single byte, a word, etc.?




More information about the ubuntu-users mailing list