Home » Infrastructure » Unix » tail command and time stamp
tail command and time stamp [message #313137] Thu, 10 April 2008 17:28 Go to next message
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 #313138 is a reply to message #313137] Thu, 10 April 2008 17:31 Go to previous messageGo to next message
ebrian
Messages: 2794
Registered: April 2006
Senior Member
You may want to post your Unix/Linux scripting questions on a Unix/Linux forum.
Re: tail command and time stamp [message #314474 is a reply to message #313138] Wed, 16 April 2008 17:55 Go to previous messageGo to next message
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
Re: tail command and time stamp [message #314734 is a reply to message #314474] Thu, 17 April 2008 12:04 Go to previous message
shree_z
Messages: 75
Registered: February 2008
Member
Thank you Andrew..
Previous Topic: Starting & Stopping DB using Script
Next Topic: extracting substring from a filename
Goto Forum:
  


Current Time: Thu Mar 28 05:09:01 CDT 2024