|
From: valdemirs on 6 Jun 2006 21:50 How could I get the greatest number in a file ? Example: cat file1 55 82 34 18 61 # cat file1 | ./gn 82 Thanks !
From: Glenn Jackman on 6 Jun 2006 23:03 At 2006-06-06 09:50PM, valdemirs(a)gmail.com <valdemirs(a)gmail.com> wrote: > How could I get the greatest number in a file ? Example: > > cat file1 > > 55 > 82 > 34 > 18 > 61 > > # cat file1 | ./gn sort -n file1 | tail -n 1 -- Glenn Jackman Ulterior Designer
From: Ed Morton on 6 Jun 2006 23:06 valdemirs(a)gmail.com wrote: > How could I get the greatest number in a file ? Example: > > cat file1 > > 55 > 82 > 34 > 18 > 61 > > # cat file1 | ./gn > > 82 > > > Thanks ! > $ cat file 55 82 34 18 61 $ sort -rn file | head -1 82 $ awk '$0+0>max{max=$0}END{print max}' file 82 Regards, Ed.
From: Chris F.A. Johnson on 6 Jun 2006 23:33 On 2006-06-07, valdemirs(a)gmail.com wrote: > How could I get the greatest number in a file ? Example: > > cat file1 > > 55 > 82 > 34 > 18 > 61 > > # cat file1 | ./gn > > 82 sort -rn file1 | { read n; echo $n; } Or: awk '$1 > max { max = $1 } END { print max }' file1 -- Chris F.A. Johnson, author <http://cfaj.freeshell.org> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence
From: John W. Krahn on 7 Jun 2006 20:35
valdemirs(a)gmail.com wrote: > How could I get the greatest number in a file ? Example: > > cat file1 > > 55 > 82 > 34 > 18 > 61 > > # cat file1 | ./gn > > 82 john(a)d154-20-154-176:~> echo "55 82 34 18 61" | perl -lne'$max = $_ if $max < $_}{print $max' 82 John -- use Perl; program fulfillment |