sfaqih
November 10, 2008, 7:23am
1
Dear Friends,
Below is the output:
901
9010
9010
9011
9011
9011
9012
9013
9014
9015
9016
9017
9018
9019
902
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
903
903
9030
9031
904
904
905
906
907
908
909
and I need to find the greatest number in the list then add 1.
I'm waiting for your kind feedback, Please .....
sfaqih
November 10, 2008, 7:25am
2
well, as you can see that greatest number is 9031.
How to find that in unix.
chella
November 10, 2008, 7:50am
3
Hi,
Here is a small suggestion for your question,
Sort the file and use the tail command to take the greatest one and add 1 to it.
Hope this helps you.
Regards,
Chella.
danmero
November 10, 2008, 7:53am
4
Classic using sort and head
sort -nr filename |head -1
or awk
awk 'x < $1{x=$1}END{print x}' filename
.. how you add 1 is your homework.
sort -nr input |
{
read
printf "%d\n" $(($REPLY+1))
}
But some shells do not support a standalone read, others the $(()) expansion,
so you'll need something like:
sort -rn input |
{
read x
printf "%d\n" `expr "$x" + 1`
}
Some recent shells support the following syntax too:
sort -nr input |
{
read
printf "%d\n" $((++REPLY))
}
With zsh you can write something like this:
x=${${(n)$(<input)}[-1]}; print $((++x))