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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find the most recent file from a list of files

Status
Not open for further replies.

mpramods

Technical User
Jun 3, 2003
50
0
0
US
I have a file that is generated every week. Its name is going to be in the following format:
${businessname}${datecreated}7890.

e.g.

SCF2004010207890.dat
SCF2004010907890.dat
SCF2004011607890.dat
SCF2004012307890.dat
SCF2004013007890.dat

The businessname & last four digits are going to remain same except the date is going to change every week.

Every week I have to run a job to load the most recent file from the above list.
How can I find the most recent file from the above list and export it to the main job.


Thanks,
mp
 
cat list|sort -r|line
or
ls -t|line
 
try this :
[tt]
ls -1 SCF*7890.dat | head +1
[/tt]


Jean Pierre.
 
sort myFile | tail -1

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I forgot to mention that this is not a list but the files in a directory.

So I cannot say cat list.

I have to export this filename from the unix script, so that the main job will pick this as the source file every time it runs.

Thanks
mp
 
LATEST_FILE=`ls -lat sap*| head -1|awk '{ print $9 }'`
export LATEST_FILE

alan
 
sort -n +0.4 data -r | line

to reverse sort and pop off the most recent file name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top