Finding files before a certain date with predefined format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding files before a certain date with predefined format
# 1  
Old 12-01-2011
Finding files before a certain date with predefined format

Guys,

I have an input file such as below

Quote:
60107110453| 2011-11-28 17:21:09
60107127568| 2011-11-27 23:59:59
60107012278| 2011-11-23 23:59:59
60127352840| 2011-11-24 23:59:59
60147017527| 2011-11-25 18:02:24
60129913070| 2011-11-24 23:59:59
60173205850| 2011-11-25 17:46:37
60173189153| 2011-11-28 09:53:35
60147850001| 2011-05-05 06:10:19
60147850379| 2011-01-12 16:00:27
60147850484| 2011-01-09 19:56:42
60147850794| 2010-11-23 23:59:59
60147851002| 2010-11-01 23:59:59
60147851046| 2010-11-19 23:59:59
60147851070| 2010-08-31 23:59:59
60147851923| 2010-10-09 23:59:59
I would like to know how i would be able to find items created before 2011-10-01

Appreciate any expert advice. Thanks.
# 2  
Old 12-02-2011
Code:
# while read x; do [ `echo $x | sed 's/-//g' | awk '{print $2}'` -lt 20111001 ] && echo $x; done < inputfile
60147850001| 2011-05-05 06:10:19
60147850379| 2011-01-12 16:00:27
60147850484| 2011-01-09 19:56:42
60147850794| 2010-11-23 23:59:59
60147851002| 2010-11-01 23:59:59
60147851046| 2010-11-19 23:59:59
60147851070| 2010-08-31 23:59:59
60147851923| 2010-10-09 23:59:59

# 3  
Old 12-02-2011
Fortunately you have date in YYYY-MM-DD format so a simple string compare will work:

Code:
$ awk '$2 < "2011-10"' infile
60147850001| 2011-05-05 06:10:19
60147850379| 2011-01-12 16:00:27
60147850484| 2011-01-09 19:56:42
60147850794| 2010-11-23 23:59:59
60147851002| 2010-11-01 23:59:59
60147851046| 2010-11-19 23:59:59
60147851070| 2010-08-31 23:59:59
60147851923| 2010-10-09 23:59:59

# 4  
Old 12-02-2011
excellent. thanks guys
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

2. Shell Programming and Scripting

Finding files and sorting by date (find | awk)

I am wanting to search a directory tree and return files that are older than a specified datetime. So far straight forward with find, now I want to sort in date order and format the output. So far I have this, but is not working and there is a problem with "." in the file and/or path names. ... (2 Replies)
Discussion started by: larry2311
2 Replies

3. UNIX for Advanced & Expert Users

Finding/Grep on files with date and hour in the file name

Hi, I have a folder structure as follows, DATA -> 2012-01-01 -> 00 -> ABC_2012-01-03_00.txt -> 01 -> ABC_2012-01-03_01.txt -> 02 -> ABC_2012-01-03_02.txt ... -> 23 -> ABC_2012-01-03_02.txt -> 2012-01-02 ... (1 Reply)
Discussion started by: mihirvora16
1 Replies

4. Shell Programming and Scripting

Finding/Grep on files with date and hour in the file name

Hi, I have a folder structure as follows, DATA -> 2012-01-01 -> 00 -> ABC_2012-01-03_00.txt -> 01 -> ABC_2012-01-03_01.txt -> 02 -> ABC_2012-01-03_02.txt ... -> 23 -> ABC_2012-01-03_02.txt -> 2012-01-02 -> 2012-01-03 So the dir DATA contains the above hierarchy, User input Start and... (6 Replies)
Discussion started by: mihirvora16
6 Replies

5. Shell Programming and Scripting

finding date numeral from file and check the validity of date format

hi there I have file names in different format as below triss_20111117_fxcb.csv triss_fxcb_20111117.csv xpnl_hypo_reu_miplvdone_11172011.csv xpnl_hypo_reu_miplvdone_11-17-2011.csv xpnl_hypo_reu_miplvdone_20111117.csv xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Discussion started by: manas_ranjan
10 Replies

6. Shell Programming and Scripting

finding the files based on date..

Hi to every one , i had ascenario like this.. i had path like export/home/pmutv/test/ in this i will recive 43 files daily with each file having that days date i.e like product.sh.20110512 like this i will 43 files every day i had to find the files. if files are avaliable i... (2 Replies)
Discussion started by: apple2685
2 Replies

7. Shell Programming and Scripting

Finding files with filename format

hi all, i'm trying to find out how to show files having a particular format. i.e. files o570345.out o5703451.out XX_570345_1.RTF so when i search for files using ls *570345* it shows all three files but actually i don't like to see the second file o5703451.out because 5703451 is... (6 Replies)
Discussion started by: adshocker
6 Replies

8. Shell Programming and Scripting

Finding files for a date

Hi, I have a directory with files from past 2 years.I need to find all the files for a specific date . Due to certain reasons I could not use this command in my process find . -type f \( -newer /tmp/May-1-2007 -a ! -newer... (4 Replies)
Discussion started by: Raamc
4 Replies

9. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

10. Shell Programming and Scripting

How to Sort files based on predefined values.?

How to Sort files based on predefined values.? Normally Sorting happens for the alphabetic or numberic orders.. Is there any way to sort a fields based on the Field values..? Field10 has : one two three five four six ten seven eight nine. in predefined order { one, two, three,... (2 Replies)
Discussion started by: p_prathaban
2 Replies
Login or Register to Ask a Question