Computing.Net > Forums > Unix > Getting Max record from a file

Getting Max record from a file

Reply to Message Icon

Original Message
Name: anilcgowda
Date: August 25, 2005 at 11:09:47 Pacific
Subject: Getting Max record from a file
OS: UNIX
CPU/Ram: 1GB
Comment:

Hi,

I have a file with sequence numbers in it. I want to insert few more sequence numbers from a new file checking the maximum sequence numbers available in the file.

Example:
oldfile.txt has
100
101
102
newfile.txt has
103
104..

I want to check if the numbers in the newfile.txt is greater than the maximum number in oldfile.txt and and if they are not already there, then insert these new numbers into the oldfile.txt

I don't know how to determine the max record in a file and how to compare this.

Can somebody help me in achieving the above task.

Thanks,
Anil



Report Offensive Message For Removal


Response Number 1
Name: David Perry
Date: August 26, 2005 at 07:25:35 Pacific
Reply: (edit)

max=`sort -nr num.txt | head -1`

where num.txt looks like

100
101
102


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Getting Max record from a file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge