find file with date and recursive search for a text

Hey Guyz I have a requirement something like this..

a part of file name, date of modification of that file and a text is entered as input.
like

Date : 080206 (MMDDYY format.)
filename : hotel_rates
text : Jim

now the file hotel_rates.ZZZ.123 (creation date is Aug 02 2006) should be found first and then the file should be opened in a read olny mode pointing to the first occurance of text 'Jim' in that file. when we press 'n' the next occurance of Jim should be visible and so on until the EOF. once searching Jim is done when we press q the control should be back to program.

all the files will be located in an archive folder with name /archive
and there'll be files with different dates like
hote_rates.XXX.333 Aug 01 2006
hotel_rates.YYY.222 Jul 30 2006
hotel_rates.ZZZ.123 Aug 02 2006
logistic_rates.ZZZ.123
logistic_rates.SSS.134

Now for the above example the file hotel_rates.ZZZ.123 should be found and it should be pinting to first occurance of Jim in that file after the user enters the input and hits enter.

Let me know if I made myself clear here..

Thanks,
Ronnie

First of all, it sounds like homework, then sorry, we dont help in homework stuff.

Secondly, I want you to make it clear if this is the standard format of filename, hotel_rates.ZZZ.123 Aug 02 2006 ie filename and creation date? If answer is yes, then why you want to take input from user in 080206 format? Take input from user in XXX 99 9999 format means Aug 02 2006 format. If answer is no, then let me tell you that in UNIX there is nothing like creation date, we have mtime(modification), ctime(change) and atime(access time) in unix, so we can try to find your files on mtime basis.

I doubt that its the standard file format in your archive directory Filename + creation date, please confirm that, because it matters.

Regards,
Tayyab

Hi Tayyab,

This is not a home work question. I started working in Unix just 6 months back. We have a daily synchronization of information with-in the internal systems of our company. like we recieve files like hotel_rates.ZZZ and once we post this data to database the file is stored in archive folder as (with a random 3 digit extention) hotel_rates.ZZZ.123 and once this file is pushed to archive folder there is no chance of modification. some times we might need to look up some information in these files which we posted, so This coding is a part of that.
We would need to retrieve the file with mtime.
so according to your notes, If we take the input as Aug 02 2006 would be better rather than 080206 right ?
let me know how to track the file and open it in readonly mode for recursive search (can we use 'less' in the shell script?)

hey I did this..

find . -name \*hotel_rates.* | xargs ls -lt | grep "Aug 02 2006"

this gives me ..
-rw-rw-r-- 1 user group 1025 Aug 02 2006 ./hotel_rates.ZZZ.147

can some one tell me how do I cut the file name from this line plz ???

assuming the file name has no embedded blanks:

find . -name \*hotel_rates.* | xargs ls -lt | nawk '/Aug 02 2006/ { print $NF }'

Cool Thanks man !!

hey how do we open a file and point it to a text/string we are searching..

for eg. we are searching for a string 'Jim' in file xxx.txt

in a shell program we have to open this file in read only mode and point it to first occurance of 'Jim'

like we do 'less xx.txt' and then type '/Jim' to find the occurance;...

vi -R -c'/Jim' xx.txt

what is 'it' refering to in the sentense above?

it refers to the control of the program....
I meant the cursor should be at the first occurance of 'Jim'

what is 'the program'? UNIX utility? Which?
'The cursor' of what? Editor, pager? And if so - which one in particular?