How to pick the latest file with date as one among the file name.( not exactly present date.)?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to pick the latest file with date as one among the file name.( not exactly present date.)?
# 1  
Old 11-20-2013
How to pick the latest file with date as one among the file name.( not exactly present date.)?

i have files like

Code:
1)20131112_abc_01.csv and
2)20131113_abc_01.csv and
3)20131113_abc_02.csv


when i try to fetch the file in the next day. it shud pick the third file..

plz help me..

and i use `date +"%Y%m%d"` command to fetch..it fetches the current date...

Last edited by Scott; 11-20-2013 at 09:43 AM.. Reason: Please use code tags
# 2  
Old 11-20-2013
How about simply using tail -1? Looks like they are correctly sorted.
# 3  
Old 11-20-2013
but it partially solves..

it is picking up second file, instead of 3rd

---------- Post updated at 08:37 AM ---------- Previous update was at 07:52 AM ----------

never mind..

i have used | sort -nr | at the end.

which picked up 3 rd file..

thanks!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

2. Shell Programming and Scripting

Find the latest file based on the date in the filename

Hi, We've a list of files that gets created on a weekly basis and it has got a date and time embedded to it. Below are the examples. I want to find out how to get the latest files get the date and time stamp out of it. Files are PQR123.PLL.M989898.201308012254.gpg... (1 Reply)
Discussion started by: rudoraj
1 Replies

3. UNIX for Advanced & Expert Users

Want to download a latest file with current date from FTP location

Dear Friends, I need help to write a shell / perl script to download the files from FTP location, having different file names (date inside the file name). Example: Mar 5 09:24 cfx_03052013_return_file.txt Mar 6 02:13 cfx_03062013_return_file.txt Mar 7 06:40... (3 Replies)
Discussion started by: Praveen Pandit
3 Replies

4. Shell Programming and Scripting

Needed shell script to get the latest file based on date

hi i need the shell script to get the file with latest date. for example in my input folder i have files like file_20130212.txt file_20130211.txt now my output folder should have the file with latest date i.e..file_20120212.txt i want to get the latest file .. i.e is should take... (6 Replies)
Discussion started by: hemanthsaikumar
6 Replies

5. Shell Programming and Scripting

Script pick elements according to the date in file

Hello, i am having file details having elements mentioned below Asia jan 18 Europe Jan 19 America Jan 20 I made script but it picks all the elements, i want to pick the elements according to the date to run the script i made cron job. Please advise how it can work.... (12 Replies)
Discussion started by: rajjev_saini123
12 Replies

6. UNIX for Dummies Questions & Answers

Selecting the file of latest Date

Hi Folks, I have one query that there is a folder in which daily several logs files are getting created , I reached to that location through putty but what I observer that 10 files of different date are been created with same name , what I need to see is the latest file ...let say the location is ... (5 Replies)
Discussion started by: KAREENA18
5 Replies

7. Shell Programming and Scripting

Pick out the various extension file from log of the same date

extension file from log (3 Replies)
Discussion started by: NehaKrish
3 Replies

8. Shell Programming and Scripting

RSYNC syntax for pushing file with latest system date

OK, I am a little new to AIX 5.3 and also to scripting. I have a shell script that I wrote and am having difficulty pushing specific files by the system date. Here is my script: #!/usr/bin/sh RSYNC=/usr/local/bin/rsync SSH=/usr/local/bin/ssh KEY=<path> somekey.key RUSER=mike... (4 Replies)
Discussion started by: tfort73
4 Replies

9. Shell Programming and Scripting

grep latest file based on date.

hi all, not sure if this has been posted b4 but i try to search but not valid. this is my question: when i do a ls -ltr there will be a list generated as follows: -rw-r--r-- 1 root sys 923260 Jan 10 04:38 FilePolling.41025.083TL021.xml -rw-r--r-- 1 root sys 1761337 Jan 10 04:40... (12 Replies)
Discussion started by: lweegp
12 Replies

10. UNIX for Dummies Questions & Answers

get the latest file by reading the date in the filename.

Hi, I grep for a pattern in a list of files. "grep -i -l $pattern *.datx*" it may give me n number of files. say for eg, it gives me 2 files. lock_eicu_20071228_00000000.dat_20071228_05343100 lock_eicu_20080501_00000000.dat_20080501_05343900 out of these 2 files I need to get the... (7 Replies)
Discussion started by: prsshini
7 Replies
Login or Register to Ask a Question