Home » Infrastructure » Unix » extracting substring from a filename (Solaris)
extracting substring from a filename [message #315765] Tue, 22 April 2008 13:30 Go to next message
beetel
Messages: 96
Registered: April 2007
Member
Hi,
I am a beginner in Unix so please bear with me...
I have a directory which has files in format: RECF-YYYY-MM-DD-input. For example, RECF-2008-02-25-input. I need to extract the YYYYY-MM-DD substring from this filename and convert that into date and compare it with a date. How do I do that?
For instance, I have a directory with the following files:
RECF-2008-02-21-input
RECF-2008-02-22-input
RECF-2008-02-23-input
RECF-2008-02-24-input


I need to get the files whose date substrings are greater than 2008-02-22 (Feb 22, 2008) which are RECF-2008-02-23-input and RECF-2008-02-24-input in the examples above. Please help Smile

Thanks in advance.


Re: extracting substring from a filename [message #315774 is a reply to message #315765] Tue, 22 April 2008 14:05 Go to previous messageGo to next message
Michel Cadot
Messages: 64111
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
I am a beginner in Unix so please bear with me...

And this is an Oracle forum, so you should choose an Unix forum to post your question.

Regards
Michel
Re: extracting substring from a filename [message #316099 is a reply to message #315774] Wed, 23 April 2008 14:36 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Date arithmetic is shell scripting is really difficult. Most solutions I've seen use perl or whatever the person is comfortable with.

http://flux.org.uk/howto/perl/yesterday_date

Fortunately if you have 4 digit year, 2 digit month & day, then you have an easy job. Keep them in decending order of significance like you have them (yyyy mm dd), then string comparison of 2 dates will give the result you are after.

See http://www.orafaq.com/forum/t/100585/45693/ for ideas.

To compare files based on last mod time, you can touch a reference file with your own time (touch -t), then use (find -newer ...) to identify your files newer than that.
Re: extracting substring from a filename [message #316102 is a reply to message #316099] Wed, 23 April 2008 14:43 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
by the way... Using touch & newer allows you to have fine granularity with time.

find -mtime allows integers, so 24 hr is your granularity. As you are interested in the date contained in the filename - not the file date, then you need to work with the filename and the string sort like mentioned.
Previous Topic: tail command and time stamp
Next Topic: unable to pass flexfield values from report wrapper to oracle applications seeded report
Goto Forum:
  


Current Time: Mon Dec 05 13:11:33 CST 2016

Total time taken to generate the page: 0.05440 seconds