find file with date and recursive search for a text


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users find file with date and recursive search for a text
# 1  
Old 08-14-2006
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
# 2  
Old 08-15-2006
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
# 3  
Old 08-15-2006
Not a homwork

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?)
# 4  
Old 08-15-2006
i did this

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 ???
# 5  
Old 08-15-2006
assuming the file name has no embedded blanks:
Code:
find . -name \*hotel_rates.* | xargs ls -lt | nawk '/Aug 02 2006/ { print $NF }'

# 6  
Old 08-15-2006
works

Cool Thanks man !!
# 7  
Old 08-16-2006
question

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;...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

2. Shell Programming and Scripting

Recursive folder search faster than find?

I'm trying to find folders created by a propritary data aquisition software with the .aps ending--yes, I have never encountered folder with a suffix before (some files also end in .aps) and sort them by date. I need the whole path ls -dt "$dataDir"*".aps"does exactly what I want except for the... (2 Replies)
Discussion started by: Michael Stora
2 Replies

3. UNIX for Dummies Questions & Answers

Help needed - find command for recursive search

Hi All I have a requirement to find the file that are most latest to be modified in each directory. Can somebody help with the command please? E.g of the problem. The directory A is having sub directory which are having subdirectory an so on. I need a command which will find the... (2 Replies)
Discussion started by: sudeep.id
2 Replies

4. Shell Programming and Scripting

Recursive search for string in file with Loop condition

Hi, Need some help... I want to execute sequence commands, like below test1.sh test2.sh ...etc test1.sh file will generate log file, we need to search for 'complete' string on test1.sh file, once that condition success and then it should go to test2.sh file, each .sh scripts will take... (5 Replies)
Discussion started by: rkrish123
5 Replies

5. UNIX for Dummies Questions & Answers

Recursive Find on file size

Is there a way to use the find command to recursively scan directories for files greater than 1Gb in size and print out the directory path and file name only? Thanks in advance. (6 Replies)
Discussion started by: jimbojames
6 Replies

6. Shell Programming and Scripting

Recursive find / grep within a file / count of a string

Hi All, This is the first time I have posted to this forum so please bear with me. Thanks also advance for any help or guidance. For a project I need to do the following. 1. There are multiple files in multiple locations so I need to find them and the location. So I had planned to use... (9 Replies)
Discussion started by: Charlie6742
9 Replies

7. Shell Programming and Scripting

bash script to find date based on search string for continuesly updating file

Hi All, I am very new to UNIX and I have tried this for a longtime now and unable to crack it.... There is a file that is continuously updating. I need to search for the string and find the date @ which it updated every day..... eg: String is "work started" The log entry is as below: ... (1 Reply)
Discussion started by: Nithz
1 Replies

8. UNIX for Advanced & Expert Users

Recursive directory search using ls instead of find

I was working on a shell script and found that the find command took too long, especially when I had to execute it multiple times. After some thought and research I came up with two functions. fileScan() filescan will cd into a directory and perform any operations you would like from within... (8 Replies)
Discussion started by: newreverie
8 Replies

9. Shell Programming and Scripting

How to find the latest file on Unix or Linux (recursive)

Hi all, I need to get the latest file. I have found this command "ls -lrt" that is great but not recursive. Can anyone help? Thanx by advance. (7 Replies)
Discussion started by: 1or2is3
7 Replies

10. Shell Programming and Scripting

How to script to find the newer date in a text file?

Hi, I have a text file, foo.txt, it looks something like below. In the file there is a line that gives the date in the form of: Mon Jun 15 11:09:31 2008. I need to find which date is the newest and then store certain details of that list data to another file. So, in this sample text file, I... (6 Replies)
Discussion started by: boolean2222
6 Replies
Login or Register to Ask a Question