tail command and time stamp [message #313137] |
Thu, 10 April 2008 17:28 |
shree_z
Messages: 75 Registered: February 2008
|
Member |
|
|
Hi all i am using the following code to get the files from a directory
ls -lrt A*.txt | tail -1 | awk '{print $9}' | read fname
Is the format correct?.
ALso the files in the directory are now being named with time on them. So my problem is for eg:
I have a file with "A.20080410.0700.txt"(file name appended with date 10th april) and "A.20080408.0700.txt" (file name appended with date 8th april)
if "A.20080408.0700.txt" was inserted into the directory after A.20080410.0700.txt, the program takes "A.20080408.0700.txt" first for processing irrespective of the date and time appended to the filename.(where as I expect the program to process "A.20080410.0700.txt" first)
I need the program in such a way that it pulls the file in accordance with the date and time appended to the file name rather than processing the file in the order in which they were generated in the directory.
How can I get this done?
Thanks in advance.
|
|
|
|
Re: tail command and time stamp [message #314474 is a reply to message #313138] |
Wed, 16 April 2008 17:55 |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
# reverse timestamp order
my-unix-ksh> ls -ltr *.*.*.txt | awk '{ print $9 }'
A.20080408.0700.txt
A.20080410.0700.txt
A.20080409.0700.txt
B.20080409.0500.txt
A.20080409.0800.txt
#Numeric sort on the 2nd + 3rd fields of the filename, using "." as delimiter. Fields start at 0
my-unix-ksh> ls -l *.*.*.txt | awk '{ print $9 }' | sort -t . -n +1 -3
A.20080408.0700.txt
B.20080409.0500.txt
A.20080409.0700.txt
A.20080409.0800.txt
A.20080410.0700.txt
Then just use your tail -1
|
|
|
|