Finding the maximum timestamp in a folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding the maximum timestamp in a folder
# 1  
Old 07-09-2013
Finding the maximum timestamp in a folder

I've the files in a directory in the following format having date +%Y%m%d%H
YR_MNTH_2013061205
YR_MNTH_2013060107
and i need the latest file i.e; YR_MNTH_2013061205 to be moved to another folder
Code:
#!/bin/ksh 
# Ksh 88 Version
for test_time in YR*
do
 ---
done

How can i achieve that !
Thank You .
# 2  
Old 07-09-2013
Hi,

Could you please provide a few more sample file names? Do all the files start with YR_MNTH or do you have other files like YR_ABCD* and so on?

Can we use "_" as delimiter to manipulate and get the maximum timestamp? Will there be always 3 fields considering "_" as delimiter (i.e., NO file of the format YR_2012030407 or YR_MNTH_ABC_2012040806)
# 3  
Old 07-09-2013
Hello Smile689,

Could you please try the following code hope it wil be helpful for you.


Code:
 
$ cat delete_latest_file.ksh

####Script starts from here#####
value=`ls -ltr | grep "YR_MNTH_*" | grep -v "grep" | awk '{print$9}' | tail -1`
 
###in case you want to see which file is going to move as follows###
echo $value
 
###moving the file ###
mv ${value} /home/test_user
 
####Script ended here#####




Could you please try this and let me know if I can help further on same.




Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cd to Folder based on TimeStamp

Hi, ls -ltr -rw-rw---- 1 user1 admins 5000032 Jan 20 17:11 M1120252_P004640.csv Now i wish to cd to that folder amongst the below folders that would have log files for the date of the .csv file i.e. 20 Jan 17:11 ls -ltr total 53616 drwxrwx--- 2 user1 admins 20840448 Jan 19... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

Extracting files having maximum timestamp

Hi , I'm using Ksh 88 I've the following files in a directory with YearMonthDate (Ex:20130601) YDT:FILE1:20130601 YDT:FILE1:20130615 YDT:FILE2:20130601 YDT:FILE2:20130615 YDT:FILE3:20130601 YDT:FILE3:20130615 And i need the files having maximum timestamp , Means i need to display ... (8 Replies)
Discussion started by: smile689
8 Replies

3. UNIX for Dummies Questions & Answers

Finding maximum occurrence value using awk

Hi everyone, I'm a new member at the forum I mistakenly posted this elsewhere too. I have a file like this: field 2 values are either 0 or negative. file test4: 100815 -20 118125 0 143616 0 154488 0 154488 0 154488 -6 196492 -5 196492 -9 196492 -7 27332 0... (5 Replies)
Discussion started by: meet77
5 Replies

4. Answers to Frequently Asked Questions

Finding maximum occurrence value using awk

Hi everyone, I'm a new member at the forum I have a file like this: field 2 values are either 0 or negative. file test4: 100815 -20 118125 0 143616 0 154488 0 154488 0 154488 -6 196492 -5 196492 -9 196492 -7 27332 0 29397 0 I would like to print a... (1 Reply)
Discussion started by: meet77
1 Replies

5. Shell Programming and Scripting

Finding minimum maximum and average

I am trying to find the minimum maximum and average from one file which has values Received message from https://www.demandmatrix.net/app/dm/xml] in milliseconds. Received message from https://www.demandmatrix.net/app/dm/xml] in milliseconds. Received message from... (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

6. Solaris

Maximum limit for allocation of groups to a folder in solaris 10

Hi, As per my knowledge, the maximum number of groups that can be allocated to a folder (in Solaris 10) is 16. But I wonder how this rule is applicable to folders which are mounted on NFS which can be accessed by 100s of groups? or is there is a restriction present? I have never handled such a... (5 Replies)
Discussion started by: poga
5 Replies

7. Shell Programming and Scripting

Finding Maximum value in a column

Hello, I am trying to get a script to work which will find the maximum value of the fourth column and assign that value to all rows where the first three columns match. For example: 1111 2222 AAAA 0.3 3333 4444 BBBB 0.7 1111 2222 AAAA 0.9 1111 2222 AAAA 0.5 3333 4444 BBBB 0.4 should... (8 Replies)
Discussion started by: jaysean
8 Replies

8. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

9. UNIX for Dummies Questions & Answers

timestamp in the end of a folder

hello everybody, im new here... can u tell me how can i add a timestamp in a bottom of a file which will say for example..it was written on that date and time. is tha possible?? thanxxxxxx (7 Replies)
Discussion started by: psychobeauty
7 Replies

10. UNIX for Dummies Questions & Answers

Unix shell script for finding top ten files of maximum size

I need to write a Unix shell script which will list top 10 files in a directory tree on basis of size. i.e. first file should be the biggest in the whole directory and all its sub directories. Please suggest any ideas (10 Replies)
Discussion started by: abhilashnair
10 Replies
Login or Register to Ask a Question