Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Last File

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
I have two files, one of which contains a key value which I need to search for in the other file. From that other file I can have multiple matches so need to sort on an existing date field and then select the LAST entry for each match to a key value.

I'm down to the matching process - in other words, I've selected the key values from the first file, selected the matching records from the second file ... but can't figure out how to get just the last one in the list (they are sorted in date order).

Thoughts?

Thanks in advance as always.

Tom

"My mind is like a steel whatchamacallit ...
 
aren't you actually asking for 'tail -1' ?

to get the last line of 'ls':
Code:
ls -1 | sed '$!d'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Something like...
Code:
#!/bin/ksh

KEY=$(<keyfile.txt)

LAST=$(grep ${KEY} otherfile.txt | last -1)
 
vgersh99: I could, of course, use tail -1 as you suggested ... however, if I have more than one batch of records - in other words, my key values may be 17, 22, 44 and I have multiples of each in a single file and I want to select only the last for each key value - tail won't work for anything other than the last one in the sequence. Good thought, though.

SamBones: interesting thought, obviously I hadn't come up with that. Will give it a shot tomorrow or Monday (I have an all day meeting tomorrow which is going to wipe me out I suspect).

Thanks to both of you!!!

Tom

"My mind is like a steel whatchamacallit ...
 
And what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
if you could define the 'batch of records' - it could helpful.
Also posting a sample input and a desired output with explanations is also helpful.

This is just an observation and nothing more.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Would love to be able to post a sample but it is HIPAA protected PHI so can't ... I'll try to dummy up a file to show you what I'm trying to do.

As to what I've tried so far, the .ksh script and Perl to extract specific field values and trying to build a key ... didn't work well although I have seen what I think is a bug, just haven't had time to work through it logically yet. Too much work to do, way too little time ... the story of all of our lives I suspect.

Tnx.

Tom

"My mind is like a steel whatchamacallit ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top