Find files older than X with a weird file format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find files older than X with a weird file format
# 1  
Old 12-16-2010
Find files older than X with a weird file format

I have an issue with a korn shell script that I am writing. The script parses through a configuration file which lists a heap of path/directories for some files which need to be FTP'd. Now the script needs to check whether there are any files which have not been processed and are X minutes old.

The problem is the format of the file is written to be passed into java in the configuration script and I cannot change it.

A few examples:
FTP.Thread.1.File.6.FileName=^WMSDATAFILE_[0-9]{4,6}_To_SuppIn_[0-9]{17}\.dat$
FTP.Thread.1.File.6.LocalDirName=data_to/MOVE/SuppIn

FTP.Thread.2.File.3.FileName=^POSDATAFILE_To_PurchOrderIn_[0-9]{17}\.xml$
FTP.Thread.2.File.3.LocalDirName=data_to/PMS/POIn

Now if I have the filename I can touch a file and use the find command to see if its older as below. But find cannot understand the file format. I was thinking about string replacing certain parts of the filename with stars as the timestamp values don't really matter, but it might get hard with the [0-9] values as they are not necessarily 0-9 for example.

touch -t [datetime X mins ago] touchfile
find [filename without the crap inside] ! - newer touchfile

Any ideas?

P.S. My script already gets the filename and path from the config file. So that part is already done.

P.S.S. Unfortunately I cannot use the -regex in my find..... as the below statement would have worked:
find ./ -regextype posix-extended -regex './XXX_[0-9]{4,6}_XXX.dat' -print

Last edited by MickAAA; 12-16-2010 at 08:12 PM..
# 2  
Old 12-16-2010
Do you have a version of awk that supports the --posix ?

Code:
$ find . -type f -print | awk --posix '/^.\/WMSDATAFILE_[0-9]{4,6}_To_SuppIn_[0-9]{17}\.dat$/ '
./WMSDATAFILE_999999_To_SuppIn_99999999999999999.dat
./WMSDATAFILE_9999_To_SuppIn_00000000000000000.dat

# 3  
Old 12-16-2010
Well it isn't giving me an error, its just not finding the files. So I guess posix exists. I will have a play and see if I can get it working

---------- Post updated at 12:37 PM ---------- Previous update was at 11:45 AM ----------

Chubler_XL, thank you for the help. I got it working:

Code:
find . -type f ! -newer touchfile -print | /usr/xpg4/bin/awk  '/^.\/WMSDATAFILE_[0-9]{4,6}_To_SuppIn_[0-9]{17}\.dat$/ '

This finds files that are older than the touchfile that match the expression.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find list of missing files based on the file format?

Hi All, In the file names we have dates. Based on the file format given by the user, if any file is not existed for a particular date with in a given interval we should consider that file is missing. I have the below files in the directory /bin/daily/voda_files. ... (9 Replies)
Discussion started by: nalu
9 Replies

2. UNIX for Dummies Questions & Answers

Find all log files under all file systems older than 2 days and zip them

Hi All, Problem Statement:Find all log files under all file systems older than 2 days and zip them. Find all zip files older than 3days and remove them. Also this has to be set under cron. I have a concerns here find . -mtime +2 -iname "*.log" -exec gzip {} Not sure if this will work as... (4 Replies)
Discussion started by: saurabh.mishra
4 Replies

3. Shell Programming and Scripting

Find files older than 8 hours

I need a script to find files older than 8 hours... I know i can use mmin but the same is not working...the same only support mtime... This is the script i created..but the same is only giving 1 hour old..as I have given dt_H as 1 only...but if i give 8..it can go in -(negative)..how to get the... (5 Replies)
Discussion started by: cotton
5 Replies

4. Shell Programming and Scripting

find files older than and containing then tar.

I'm tring to: find files recursively older than x days that contain dat or DAT then tar them I can find the files older than 90 days containing dat with this: find . -mtime +90 -type f -name "*dat*" -exec tar -cvvfp /some/path/some.tar {} \; but how do I do it case insensitive? ... (3 Replies)
Discussion started by: Ikon
3 Replies

5. UNIX Desktop Questions & Answers

Find files older than 10 days

What command arguments I can use in unix to list files older than 10 days in my current directory, but I don't want to list the hidden files. find . -type f -mtime +15 -print will work but, it is listing all the hidden files., which I don't want. (4 Replies)
Discussion started by: Pouchie1
4 Replies

6. Solaris

Find files older than x days and create a consolidated single tar file.

Hello, I need help in finding files older than x days and creating a single consolidated tar file combining them. Can anyone please provide me a script? Thanks, Dawn (3 Replies)
Discussion started by: Dawn Bosch
3 Replies

7. UNIX for Advanced & Expert Users

how to find files older than 4hours in HP-UX

Hi, I want to find the files older than 4 hours and remove them in HP-UX 11.23. Can anyone tell me how to do this? Thanks, GK (3 Replies)
Discussion started by: caprikar
3 Replies

8. Shell Programming and Scripting

find files older than a given file

I want to find out the files that are older than a given file in the current directory ...Can anyone help (5 Replies)
Discussion started by: Shivdatta
5 Replies

9. Shell Programming and Scripting

only find files older than x minutes old

I am looking for a way to show files that have been created within a certain period (say anything older than 10 minutes or so). Is there a command/series of commands I can do this with? As an example, I have the following in a directory: -rw-r--r-- 1 owner group 70175 May 16 09:10... (1 Reply)
Discussion started by: dsimpg1
1 Replies

10. Shell Programming and Scripting

Find files older than 20 days & not use find

I need to find files that have the ending of .out and that are older than 20 days. However, I cannot use find as I do not want to search in the directories that are underneath the directory that I am searching in. How can this be done?? Find returns files that I do not want. (2 Replies)
Discussion started by: halo98
2 Replies
Login or Register to Ask a Question