Most Recent File script

OK, I know next to nothing about scripting in unix, and at the moment I don't have access to a unix environment...

We have an application that generates a text report file which is later printed. The format is this:

bbtptcYYMMDDSSCC.txt (year/month/day/second/check digit)

I want a script to scan the directory these files live in (lets call it XYZ_REPORT) for the most recent of these files (bbtptc*) and append it to a file, ie BBT_EXPORT.txt. Would this script suffice? And if not, what does it need?

#!/bin/ksh
cd $XYZ_REPORT
cp `ls -t bbptc* | head -1` bbptc_extract

Thanks in advance!

That would overwrite bbptc_extract each time the script ran, not append it as you specified. Try changing the cp to:

cat `ls -t bbptc* | head -1` >> bbptc_extract

That would append the newest file to the end of a file called bbptc_extract