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

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

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:

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

where num.txt looks like

100
101
102


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home



Results for: Getting Max record from a file

getting 9 char from a file...
    Summary: Thanks a lot! This really worked. Now another related question. Now that I got my unique key into a file, I want to take that key and go against multiple files and extract record from them. Note, ...
www.computing.net/answers/unix/getting-9-char-from-a-file/6433.html

Shell Script: Get value from a file
    Summary: Hello All, I am looking for a way to get a string from a file and assign it to a variable in Shell Script. Example I have a file FILE containing A B B If I run grep -c 'B' FILE It gives...
www.computing.net/answers/unix/shell-script-get-value-from-a-file/5760.html

Get the first line from a file
    Summary: Hi All, I want to get the first line from a file and write it into another file. Please help. Thanks in advance. Regards, Raj Thanks & Regards, Raj...
www.computing.net/answers/unix/get-the-first-line-from-a-file/7981.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes Today.
Discuss in The Lounge
Poll History






Data Recovery Software