Operating System - HP-UX
1855657 Members
8697 Online
104113 Solutions
New Discussion

Re: getting the next number

 
SOLVED
Go to solution
Angela Swyers_1
Frequent Advisor

getting the next number

In a file I have a column that has numbers in it. I need to sort that column, get the largest number and add 1 to it. Anyone have any ideas how to do that?
3 REPLIES 3
Sundar_7
Honored Contributor
Solution

Re: getting the next number

Say if your file has the following format

text text2 677
text3 text4 788

then

typeset -i LARGEST=0
LARGEST=$(sort -nbk 3 inputfile | tail -1 | awk '{print $3}')
(( LARGEST=LARGEST + 1 ))
echo $LARGEST
Learn What to do ,How to do and more importantly When to do ?
Govind_3
Regular Advisor

Re: getting the next number

1)cat filename |awk '{ print $colnum }'|sort
$colnum is the column you want to select

2)cut -d" " -f$colnum |sort

-Cheers
Govind
Angela Swyers_1
Frequent Advisor

Re: getting the next number

Thank you. That got me pointed in the right direction.